Deleted Added
full compact
ip_output.c (155201) ip_output.c (158563)
1/*-
2 * Copyright (c) 1982, 1986, 1988, 1990, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 13 unchanged lines hidden (view full) ---

22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 * @(#)ip_output.c 8.3 (Berkeley) 1/21/94
1/*-
2 * Copyright (c) 1982, 1986, 1988, 1990, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 13 unchanged lines hidden (view full) ---

22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 * @(#)ip_output.c 8.3 (Berkeley) 1/21/94
30 * $FreeBSD: head/sys/netinet/ip_output.c 155201 2006-02-02 03:13:16Z csjp $
30 * $FreeBSD: head/sys/netinet/ip_output.c 158563 2006-05-14 14:22:49Z bms $
31 */
32
33#include "opt_ipfw.h"
34#include "opt_ipsec.h"
35#include "opt_mac.h"
36#include "opt_mbuf_stress_test.h"
37
38#include <sys/param.h>

--- 1094 unchanged lines hidden (view full) ---

1133/*
1134 * Given an inpcb, return its multicast options structure pointer. Accepts
1135 * an unlocked inpcb pointer, but will return it locked. May sleep.
1136 */
1137static struct ip_moptions *
1138ip_findmoptions(struct inpcb *inp)
1139{
1140 struct ip_moptions *imo;
31 */
32
33#include "opt_ipfw.h"
34#include "opt_ipsec.h"
35#include "opt_mac.h"
36#include "opt_mbuf_stress_test.h"
37
38#include <sys/param.h>

--- 1094 unchanged lines hidden (view full) ---

1133/*
1134 * Given an inpcb, return its multicast options structure pointer. Accepts
1135 * an unlocked inpcb pointer, but will return it locked. May sleep.
1136 */
1137static struct ip_moptions *
1138ip_findmoptions(struct inpcb *inp)
1139{
1140 struct ip_moptions *imo;
1141 struct in_multi **immp;
1141
1142 INP_LOCK(inp);
1143 if (inp->inp_moptions != NULL)
1144 return (inp->inp_moptions);
1145
1146 INP_UNLOCK(inp);
1147
1148 imo = (struct ip_moptions*)malloc(sizeof(*imo), M_IPMOPTS, M_WAITOK);
1142
1143 INP_LOCK(inp);
1144 if (inp->inp_moptions != NULL)
1145 return (inp->inp_moptions);
1146
1147 INP_UNLOCK(inp);
1148
1149 imo = (struct ip_moptions*)malloc(sizeof(*imo), M_IPMOPTS, M_WAITOK);
1150 immp = (struct in_multi **)malloc((sizeof(*immp) * IP_MIN_MEMBERSHIPS),
1151 M_IPMOPTS, M_WAITOK);
1149
1150 imo->imo_multicast_ifp = NULL;
1151 imo->imo_multicast_addr.s_addr = INADDR_ANY;
1152 imo->imo_multicast_vif = -1;
1153 imo->imo_multicast_ttl = IP_DEFAULT_MULTICAST_TTL;
1154 imo->imo_multicast_loop = IP_DEFAULT_MULTICAST_LOOP;
1155 imo->imo_num_memberships = 0;
1152
1153 imo->imo_multicast_ifp = NULL;
1154 imo->imo_multicast_addr.s_addr = INADDR_ANY;
1155 imo->imo_multicast_vif = -1;
1156 imo->imo_multicast_ttl = IP_DEFAULT_MULTICAST_TTL;
1157 imo->imo_multicast_loop = IP_DEFAULT_MULTICAST_LOOP;
1158 imo->imo_num_memberships = 0;
1159 imo->imo_max_memberships = IP_MIN_MEMBERSHIPS;
1160 imo->imo_membership = immp;
1156
1157 INP_LOCK(inp);
1158 if (inp->inp_moptions != NULL) {
1161
1162 INP_LOCK(inp);
1163 if (inp->inp_moptions != NULL) {
1164 free(immp, M_IPMOPTS);
1159 free(imo, M_IPMOPTS);
1160 return (inp->inp_moptions);
1161 }
1162 inp->inp_moptions = imo;
1163 return (imo);
1164}
1165
1166/*

--- 188 unchanged lines hidden (view full) ---

1355 break;
1356 }
1357 if (i < imo->imo_num_memberships) {
1358 INP_UNLOCK(inp);
1359 error = EADDRINUSE;
1360 splx(s);
1361 break;
1362 }
1165 free(imo, M_IPMOPTS);
1166 return (inp->inp_moptions);
1167 }
1168 inp->inp_moptions = imo;
1169 return (imo);
1170}
1171
1172/*

--- 188 unchanged lines hidden (view full) ---

1361 break;
1362 }
1363 if (i < imo->imo_num_memberships) {
1364 INP_UNLOCK(inp);
1365 error = EADDRINUSE;
1366 splx(s);
1367 break;
1368 }
1363 if (i == IP_MAX_MEMBERSHIPS) {
1369 if (imo->imo_num_memberships == imo->imo_max_memberships) {
1370 struct in_multi **nmships, **omships;
1371 size_t newmax;
1372 /*
1373 * Resize the vector to next power-of-two minus 1. If the
1374 * size would exceed the maximum then we know we've really
1375 * run out of entries. Otherwise, we realloc() the vector
1376 * with the INP lock held to avoid introducing a race.
1377 */
1378 nmships = NULL;
1379 omships = imo->imo_membership;
1380 newmax = ((imo->imo_max_memberships + 1) * 2) - 1;
1381 if (newmax <= IP_MAX_MEMBERSHIPS) {
1382 nmships = (struct in_multi **)realloc(omships,
1383sizeof(*nmships) * newmax, M_IPMOPTS, M_NOWAIT);
1384 if (nmships != NULL) {
1385 imo->imo_membership = nmships;
1386 imo->imo_max_memberships = newmax;
1387 }
1388 }
1389 if (nmships == NULL) {
1364 INP_UNLOCK(inp);
1365 error = ETOOMANYREFS;
1366 splx(s);
1367 break;
1390 INP_UNLOCK(inp);
1391 error = ETOOMANYREFS;
1392 splx(s);
1393 break;
1394 }
1368 }
1369 /*
1370 * Everything looks good; add a new record to the multicast
1371 * address list for the given interface.
1372 */
1373 if ((imo->imo_membership[i] =
1374 in_addmulti(&mreq.imr_multiaddr, ifp)) == NULL) {
1375 INP_UNLOCK(inp);

--- 157 unchanged lines hidden (view full) ---

1533ip_freemoptions(imo)
1534 register struct ip_moptions *imo;
1535{
1536 register int i;
1537
1538 if (imo != NULL) {
1539 for (i = 0; i < imo->imo_num_memberships; ++i)
1540 in_delmulti(imo->imo_membership[i]);
1395 }
1396 /*
1397 * Everything looks good; add a new record to the multicast
1398 * address list for the given interface.
1399 */
1400 if ((imo->imo_membership[i] =
1401 in_addmulti(&mreq.imr_multiaddr, ifp)) == NULL) {
1402 INP_UNLOCK(inp);

--- 157 unchanged lines hidden (view full) ---

1560ip_freemoptions(imo)
1561 register struct ip_moptions *imo;
1562{
1563 register int i;
1564
1565 if (imo != NULL) {
1566 for (i = 0; i < imo->imo_num_memberships; ++i)
1567 in_delmulti(imo->imo_membership[i]);
1568 free(imo->imo_membership, M_IPMOPTS);
1541 free(imo, M_IPMOPTS);
1542 }
1543}
1544
1545/*
1546 * Routine called from ip_output() to loop back a copy of an IP multicast
1547 * packet to the input queue of a specified interface. Note that this
1548 * calls the output routine of the loopback "driver", but with an interface

--- 61 unchanged lines hidden ---
1569 free(imo, M_IPMOPTS);
1570 }
1571}
1572
1573/*
1574 * Routine called from ip_output() to loop back a copy of an IP multicast
1575 * packet to the input queue of a specified interface. Note that this
1576 * calls the output routine of the loopback "driver", but with an interface

--- 61 unchanged lines hidden ---