Deleted Added
full compact
if_ethersubr.c (108107) if_ethersubr.c (109623)
1/*
2 * Copyright (c) 1982, 1989, 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

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

26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 *
33 * @(#)if_ethersubr.c 8.1 (Berkeley) 6/10/93
1/*
2 * Copyright (c) 1982, 1989, 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

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

26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 *
33 * @(#)if_ethersubr.c 8.1 (Berkeley) 6/10/93
34 * $FreeBSD: head/sys/net/if_ethersubr.c 108107 2002-12-19 22:58:27Z bmilekic $
34 * $FreeBSD: head/sys/net/if_ethersubr.c 109623 2003-01-21 08:56:16Z alfred $
35 */
36
37#include "opt_atalk.h"
38#include "opt_inet.h"
39#include "opt_inet6.h"
40#include "opt_ipx.h"
41#include "opt_bdg.h"
42#include "opt_mac.h"

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

231 /*
232 * In the phase 2 case, need to prepend an mbuf for the llc header.
233 * Since we must preserve the value of m, which is passed to us by
234 * value, we m_copy() the first mbuf, and use it for our llc header.
235 */
236 if ( aa->aa_flags & AFA_PHASE2 ) {
237 struct llc llc;
238
35 */
36
37#include "opt_atalk.h"
38#include "opt_inet.h"
39#include "opt_inet6.h"
40#include "opt_ipx.h"
41#include "opt_bdg.h"
42#include "opt_mac.h"

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

231 /*
232 * In the phase 2 case, need to prepend an mbuf for the llc header.
233 * Since we must preserve the value of m, which is passed to us by
234 * value, we m_copy() the first mbuf, and use it for our llc header.
235 */
236 if ( aa->aa_flags & AFA_PHASE2 ) {
237 struct llc llc;
238
239 M_PREPEND(m, sizeof(struct llc), M_TRYWAIT);
239 M_PREPEND(m, sizeof(struct llc), 0);
240 llc.llc_dsap = llc.llc_ssap = LLC_SNAP_LSAP;
241 llc.llc_control = LLC_UI;
242 bcopy(at_org_code, llc.llc_snap_org_code, sizeof(at_org_code));
243 llc.llc_snap_ether_type = htons( ETHERTYPE_AT );
244 bcopy(&llc, mtod(m, caddr_t), sizeof(struct llc));
245 type = htons(m->m_pkthdr.len);
246 hlen = sizeof(struct llc) + ETHER_HDR_LEN;
247 } else {

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

256 default:
257 case 0x8137: /* Novell Ethernet_II Ethernet TYPE II */
258 type = 0x8137;
259 break;
260 case 0x0: /* Novell 802.3 */
261 type = htons( m->m_pkthdr.len);
262 break;
263 case 0xe0e0: /* Novell 802.2 and Token-Ring */
240 llc.llc_dsap = llc.llc_ssap = LLC_SNAP_LSAP;
241 llc.llc_control = LLC_UI;
242 bcopy(at_org_code, llc.llc_snap_org_code, sizeof(at_org_code));
243 llc.llc_snap_ether_type = htons( ETHERTYPE_AT );
244 bcopy(&llc, mtod(m, caddr_t), sizeof(struct llc));
245 type = htons(m->m_pkthdr.len);
246 hlen = sizeof(struct llc) + ETHER_HDR_LEN;
247 } else {

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

256 default:
257 case 0x8137: /* Novell Ethernet_II Ethernet TYPE II */
258 type = 0x8137;
259 break;
260 case 0x0: /* Novell 802.3 */
261 type = htons( m->m_pkthdr.len);
262 break;
263 case 0xe0e0: /* Novell 802.2 and Token-Ring */
264 M_PREPEND(m, 3, M_TRYWAIT);
264 M_PREPEND(m, 3, 0);
265 type = htons( m->m_pkthdr.len);
266 cp = mtod(m, u_char *);
267 *cp++ = 0xE0;
268 *cp++ = 0xE0;
269 *cp++ = 0x03;
270 break;
271 }
272 bcopy((caddr_t)&(((struct sockaddr_ns *)dst)->sns_addr.x_host),

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

307 if_printf(ifp, "can't handle af%d\n", dst->sa_family);
308 senderr(EAFNOSUPPORT);
309 }
310
311 /*
312 * Add local net header. If no space in first mbuf,
313 * allocate another.
314 */
265 type = htons( m->m_pkthdr.len);
266 cp = mtod(m, u_char *);
267 *cp++ = 0xE0;
268 *cp++ = 0xE0;
269 *cp++ = 0x03;
270 break;
271 }
272 bcopy((caddr_t)&(((struct sockaddr_ns *)dst)->sns_addr.x_host),

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

307 if_printf(ifp, "can't handle af%d\n", dst->sa_family);
308 senderr(EAFNOSUPPORT);
309 }
310
311 /*
312 * Add local net header. If no space in first mbuf,
313 * allocate another.
314 */
315 M_PREPEND(m, sizeof (struct ether_header), M_DONTWAIT);
315 M_PREPEND(m, sizeof (struct ether_header), M_NOWAIT);
316 if (m == 0)
317 senderr(ENOBUFS);
318 eh = mtod(m, struct ether_header *);
319 (void)memcpy(&eh->ether_type, &type,
320 sizeof(eh->ether_type));
321 (void)memcpy(eh->ether_dhost, edst, sizeof (edst));
322 if (hdrcmplt)
323 (void)memcpy(eh->ether_shost, esrc,

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

465 args.eh = &save_eh; /* MAC header for bridged/MAC packets */
466 i = ip_fw_chk_ptr(&args);
467 m = args.m;
468 if (m != NULL) {
469 /*
470 * Restore Ethernet header, as needed, in case the
471 * mbuf chain was replaced by ipfw.
472 */
316 if (m == 0)
317 senderr(ENOBUFS);
318 eh = mtod(m, struct ether_header *);
319 (void)memcpy(&eh->ether_type, &type,
320 sizeof(eh->ether_type));
321 (void)memcpy(eh->ether_dhost, edst, sizeof (edst));
322 if (hdrcmplt)
323 (void)memcpy(eh->ether_shost, esrc,

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

465 args.eh = &save_eh; /* MAC header for bridged/MAC packets */
466 i = ip_fw_chk_ptr(&args);
467 m = args.m;
468 if (m != NULL) {
469 /*
470 * Restore Ethernet header, as needed, in case the
471 * mbuf chain was replaced by ipfw.
472 */
473 M_PREPEND(m, ETHER_HDR_LEN, M_DONTWAIT);
473 M_PREPEND(m, ETHER_HDR_LEN, M_NOWAIT);
474 if (m == NULL) {
475 *m0 = m;
476 return 0;
477 }
478 if (eh != mtod(m, struct ether_header *))
479 bcopy(&save_eh, mtod(m, struct ether_header *),
480 ETHER_HDR_LEN);
481 }

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

489 return 1;
490
491 if (DUMMYNET_LOADED && (i & IP_FW_PORT_DYNT_FLAG)) {
492 /*
493 * Pass the pkt to dummynet, which consumes it.
494 * If shared, make a copy and keep the original.
495 */
496 if (shared) {
474 if (m == NULL) {
475 *m0 = m;
476 return 0;
477 }
478 if (eh != mtod(m, struct ether_header *))
479 bcopy(&save_eh, mtod(m, struct ether_header *),
480 ETHER_HDR_LEN);
481 }

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

489 return 1;
490
491 if (DUMMYNET_LOADED && (i & IP_FW_PORT_DYNT_FLAG)) {
492 /*
493 * Pass the pkt to dummynet, which consumes it.
494 * If shared, make a copy and keep the original.
495 */
496 if (shared) {
497 m = m_copypacket(m, M_DONTWAIT);
497 m = m_copypacket(m, M_NOWAIT);
498 if (m == NULL)
499 return 0;
500 } else {
501 /*
502 * Pass the original to dummynet and
503 * nothing back to the caller
504 */
505 *m0 = NULL ;

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

889 * hand the packet to it for last chance processing;
890 * otherwise dispose of it.
891 */
892 if (ng_ether_input_orphan_p != NULL) {
893 /*
894 * Put back the ethernet header so netgraph has a
895 * consistent view of inbound packets.
896 */
498 if (m == NULL)
499 return 0;
500 } else {
501 /*
502 * Pass the original to dummynet and
503 * nothing back to the caller
504 */
505 *m0 = NULL ;

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

889 * hand the packet to it for last chance processing;
890 * otherwise dispose of it.
891 */
892 if (ng_ether_input_orphan_p != NULL) {
893 /*
894 * Put back the ethernet header so netgraph has a
895 * consistent view of inbound packets.
896 */
897 M_PREPEND(m, sizeof (struct ether_header), M_DONTWAIT);
897 M_PREPEND(m, sizeof (struct ether_header), M_NOWAIT);
898 (*ng_ether_input_orphan_p)(ifp, m);
899 return;
900 }
901 m_freem(m);
902}
903
904/*
905 * Convert Ethernet address to printable (loggable) representation.

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

1108 return 0;
1109
1110#ifdef INET
1111 case AF_INET:
1112 sin = (struct sockaddr_in *)sa;
1113 if (!IN_MULTICAST(ntohl(sin->sin_addr.s_addr)))
1114 return EADDRNOTAVAIL;
1115 MALLOC(sdl, struct sockaddr_dl *, sizeof *sdl, M_IFMADDR,
898 (*ng_ether_input_orphan_p)(ifp, m);
899 return;
900 }
901 m_freem(m);
902}
903
904/*
905 * Convert Ethernet address to printable (loggable) representation.

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

1108 return 0;
1109
1110#ifdef INET
1111 case AF_INET:
1112 sin = (struct sockaddr_in *)sa;
1113 if (!IN_MULTICAST(ntohl(sin->sin_addr.s_addr)))
1114 return EADDRNOTAVAIL;
1115 MALLOC(sdl, struct sockaddr_dl *, sizeof *sdl, M_IFMADDR,
1116 M_WAITOK|M_ZERO);
1116 M_ZERO);
1117 sdl->sdl_len = sizeof *sdl;
1118 sdl->sdl_family = AF_LINK;
1119 sdl->sdl_index = ifp->if_index;
1120 sdl->sdl_type = IFT_ETHER;
1121 sdl->sdl_alen = ETHER_ADDR_LEN;
1122 e_addr = LLADDR(sdl);
1123 ETHER_MAP_IP_MULTICAST(&sin->sin_addr, e_addr);
1124 *llsa = (struct sockaddr *)sdl;

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

1135 */
1136 ifp->if_flags |= IFF_ALLMULTI;
1137 *llsa = 0;
1138 return 0;
1139 }
1140 if (!IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr))
1141 return EADDRNOTAVAIL;
1142 MALLOC(sdl, struct sockaddr_dl *, sizeof *sdl, M_IFMADDR,
1117 sdl->sdl_len = sizeof *sdl;
1118 sdl->sdl_family = AF_LINK;
1119 sdl->sdl_index = ifp->if_index;
1120 sdl->sdl_type = IFT_ETHER;
1121 sdl->sdl_alen = ETHER_ADDR_LEN;
1122 e_addr = LLADDR(sdl);
1123 ETHER_MAP_IP_MULTICAST(&sin->sin_addr, e_addr);
1124 *llsa = (struct sockaddr *)sdl;

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

1135 */
1136 ifp->if_flags |= IFF_ALLMULTI;
1137 *llsa = 0;
1138 return 0;
1139 }
1140 if (!IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr))
1141 return EADDRNOTAVAIL;
1142 MALLOC(sdl, struct sockaddr_dl *, sizeof *sdl, M_IFMADDR,
1143 M_WAITOK|M_ZERO);
1143 M_ZERO);
1144 sdl->sdl_len = sizeof *sdl;
1145 sdl->sdl_family = AF_LINK;
1146 sdl->sdl_index = ifp->if_index;
1147 sdl->sdl_type = IFT_ETHER;
1148 sdl->sdl_alen = ETHER_ADDR_LEN;
1149 e_addr = LLADDR(sdl);
1150 ETHER_MAP_IPV6_MULTICAST(&sin6->sin6_addr, e_addr);
1151 *llsa = (struct sockaddr *)sdl;
1152 return 0;
1153#endif
1154
1155 default:
1156 /*
1157 * Well, the text isn't quite right, but it's the name
1158 * that counts...
1159 */
1160 return EAFNOSUPPORT;
1161 }
1162}
1144 sdl->sdl_len = sizeof *sdl;
1145 sdl->sdl_family = AF_LINK;
1146 sdl->sdl_index = ifp->if_index;
1147 sdl->sdl_type = IFT_ETHER;
1148 sdl->sdl_alen = ETHER_ADDR_LEN;
1149 e_addr = LLADDR(sdl);
1150 ETHER_MAP_IPV6_MULTICAST(&sin6->sin6_addr, e_addr);
1151 *llsa = (struct sockaddr *)sdl;
1152 return 0;
1153#endif
1154
1155 default:
1156 /*
1157 * Well, the text isn't quite right, but it's the name
1158 * that counts...
1159 */
1160 return EAFNOSUPPORT;
1161 }
1162}