if_vlan.c (128618) | if_vlan.c (128871) |
---|---|
1/* 2 * Copyright 1998 Massachusetts Institute of Technology 3 * 4 * Permission to use, copy, modify, and distribute this software and 5 * its documentation for any purpose and without fee is hereby 6 * granted, provided that both the above copyright notice and this 7 * permission notice appear in all copies, that both the above 8 * copyright notice and this permission notice appear in all --- 12 unchanged lines hidden (view full) --- 21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 23 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 25 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 26 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 * | 1/* 2 * Copyright 1998 Massachusetts Institute of Technology 3 * 4 * Permission to use, copy, modify, and distribute this software and 5 * its documentation for any purpose and without fee is hereby 6 * granted, provided that both the above copyright notice and this 7 * permission notice appear in all copies, that both the above 8 * copyright notice and this permission notice appear in all --- 12 unchanged lines hidden (view full) --- 21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 23 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 25 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 26 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 * |
29 * $FreeBSD: head/sys/net/if_vlan.c 128618 2004-04-24 22:24:48Z luigi $ | 29 * $FreeBSD: head/sys/net/if_vlan.c 128871 2004-05-03 13:48:35Z andre $ |
30 */ 31 32/* 33 * if_vlan.c - pseudo-device driver for IEEE 802.1Q virtual LANs. 34 * Might be extended some day to also handle IEEE 802.1p priority 35 * tagging. This is sort of sneaky in the implementation, since 36 * we need to pretend to be enough of an Ethernet implementation 37 * to make arp work. The way we do this is by telling everyone --- 82 unchanged lines hidden (view full) --- 120static void vlan_clone_destroy(struct ifnet *); 121static void vlan_start(struct ifnet *ifp); 122static void vlan_ifinit(void *foo); 123static void vlan_input(struct ifnet *ifp, struct mbuf *m); 124static int vlan_ioctl(struct ifnet *ifp, u_long cmd, caddr_t addr); 125static int vlan_setmulti(struct ifnet *ifp); 126static int vlan_unconfig(struct ifnet *ifp); 127static int vlan_config(struct ifvlan *ifv, struct ifnet *p); | 30 */ 31 32/* 33 * if_vlan.c - pseudo-device driver for IEEE 802.1Q virtual LANs. 34 * Might be extended some day to also handle IEEE 802.1p priority 35 * tagging. This is sort of sneaky in the implementation, since 36 * we need to pretend to be enough of an Ethernet implementation 37 * to make arp work. The way we do this is by telling everyone --- 82 unchanged lines hidden (view full) --- 120static void vlan_clone_destroy(struct ifnet *); 121static void vlan_start(struct ifnet *ifp); 122static void vlan_ifinit(void *foo); 123static void vlan_input(struct ifnet *ifp, struct mbuf *m); 124static int vlan_ioctl(struct ifnet *ifp, u_long cmd, caddr_t addr); 125static int vlan_setmulti(struct ifnet *ifp); 126static int vlan_unconfig(struct ifnet *ifp); 127static int vlan_config(struct ifvlan *ifv, struct ifnet *p); |
128static void vlan_link_state(struct ifnet *ifp, int link); |
|
128 129struct if_clone vlan_cloner = IF_CLONE_INITIALIZER(VLANNAME, 130 vlan_clone_create, vlan_clone_destroy, 0, IF_MAXUNIT); 131 132/* 133 * Program our multicast filter. What we're actually doing is 134 * programming the multicast filter of the parent. This has the 135 * side effect of causing the parent interface to receive multicast --- 68 unchanged lines hidden (view full) --- 204 * NB: Noone should ever need to check if vlan_input_p is null or 205 * not. This is because interfaces have a count of the number 206 * of active vlans (if_nvlans) and this should never be bumped 207 * except by vlan_config--which is in this module so therefore 208 * the module must be loaded and vlan_input_p must be non-NULL. 209 */ 210extern void (*vlan_input_p)(struct ifnet *, struct mbuf *); 211 | 129 130struct if_clone vlan_cloner = IF_CLONE_INITIALIZER(VLANNAME, 131 vlan_clone_create, vlan_clone_destroy, 0, IF_MAXUNIT); 132 133/* 134 * Program our multicast filter. What we're actually doing is 135 * programming the multicast filter of the parent. This has the 136 * side effect of causing the parent interface to receive multicast --- 68 unchanged lines hidden (view full) --- 205 * NB: Noone should ever need to check if vlan_input_p is null or 206 * not. This is because interfaces have a count of the number 207 * of active vlans (if_nvlans) and this should never be bumped 208 * except by vlan_config--which is in this module so therefore 209 * the module must be loaded and vlan_input_p must be non-NULL. 210 */ 211extern void (*vlan_input_p)(struct ifnet *, struct mbuf *); 212 |
213/* For MII eyes only... */ 214extern void (*vlan_link_state_p)(struct ifnet *, int); 215 |
|
212static int 213vlan_modevent(module_t mod, int type, void *data) 214{ 215 216 switch (type) { 217 case MOD_LOAD: 218 LIST_INIT(&ifv_list); 219 VLAN_LOCK_INIT(); 220 vlan_input_p = vlan_input; | 216static int 217vlan_modevent(module_t mod, int type, void *data) 218{ 219 220 switch (type) { 221 case MOD_LOAD: 222 LIST_INIT(&ifv_list); 223 VLAN_LOCK_INIT(); 224 vlan_input_p = vlan_input; |
225 vlan_link_state_p = vlan_link_state; |
|
221 if_clone_attach(&vlan_cloner); 222 break; 223 case MOD_UNLOAD: 224 if_clone_detach(&vlan_cloner); 225 vlan_input_p = NULL; | 226 if_clone_attach(&vlan_cloner); 227 break; 228 case MOD_UNLOAD: 229 if_clone_detach(&vlan_cloner); 230 vlan_input_p = NULL; |
231 vlan_link_state_p = NULL; |
|
226 while (!LIST_EMPTY(&ifv_list)) 227 vlan_clone_destroy(&LIST_FIRST(&ifv_list)->ifv_if); 228 VLAN_LOCK_DESTROY(); 229 break; 230 } 231 return 0; 232} 233 --- 293 unchanged lines hidden (view full) --- 527 ifv->ifv_p = p; 528 ifv->ifv_if.if_mtu = p->if_mtu - ifv->ifv_mtufudge; 529 /* 530 * Copy only a selected subset of flags from the parent. 531 * Other flags are none of our business. 532 */ 533 ifv->ifv_if.if_flags = (p->if_flags & 534 (IFF_BROADCAST | IFF_MULTICAST | IFF_SIMPLEX | IFF_POINTOPOINT)); | 232 while (!LIST_EMPTY(&ifv_list)) 233 vlan_clone_destroy(&LIST_FIRST(&ifv_list)->ifv_if); 234 VLAN_LOCK_DESTROY(); 235 break; 236 } 237 return 0; 238} 239 --- 293 unchanged lines hidden (view full) --- 533 ifv->ifv_p = p; 534 ifv->ifv_if.if_mtu = p->if_mtu - ifv->ifv_mtufudge; 535 /* 536 * Copy only a selected subset of flags from the parent. 537 * Other flags are none of our business. 538 */ 539 ifv->ifv_if.if_flags = (p->if_flags & 540 (IFF_BROADCAST | IFF_MULTICAST | IFF_SIMPLEX | IFF_POINTOPOINT)); |
541 ifv->ifv_if.if_link_state = p->if_link_state; |
|
535 536 /* 537 * If the parent interface can do hardware-assisted 538 * VLAN encapsulation, then propagate its hardware- 539 * assisted checksumming flags. 540 */ 541 if (p->if_capabilities & IFCAP_VLAN_HWTAGGING) 542 ifv->ifv_if.if_capabilities |= p->if_capabilities & IFCAP_HWCSUM; --- 74 unchanged lines hidden (view full) --- 617 } 618 } 619 } 620 621 /* Disconnect from parent. */ 622 ifv->ifv_p = NULL; 623 ifv->ifv_if.if_mtu = ETHERMTU; /* XXX why not 0? */ 624 ifv->ifv_flags = 0; | 542 543 /* 544 * If the parent interface can do hardware-assisted 545 * VLAN encapsulation, then propagate its hardware- 546 * assisted checksumming flags. 547 */ 548 if (p->if_capabilities & IFCAP_VLAN_HWTAGGING) 549 ifv->ifv_if.if_capabilities |= p->if_capabilities & IFCAP_HWCSUM; --- 74 unchanged lines hidden (view full) --- 624 } 625 } 626 } 627 628 /* Disconnect from parent. */ 629 ifv->ifv_p = NULL; 630 ifv->ifv_if.if_mtu = ETHERMTU; /* XXX why not 0? */ 631 ifv->ifv_flags = 0; |
632 ifv->ifv_if.if_link_state = LINK_STATE_UNKNOWN; |
|
625 626 /* Clear our MAC address. */ 627 ifa = ifaddr_byindex(ifv->ifv_if.if_index); 628 sdl = (struct sockaddr_dl *)ifa->ifa_addr; 629 sdl->sdl_type = IFT_ETHER; 630 sdl->sdl_alen = ETHER_ADDR_LEN; 631 bzero(LLADDR(sdl), ETHER_ADDR_LEN); 632 bzero(ifv->ifv_ac.ac_enaddr, ETHER_ADDR_LEN); --- 19 unchanged lines hidden (view full) --- 652 if (error == 0) 653 ifv->ifv_flags &= ~IFVF_PROMISC; 654 } 655 } 656 657 return (error); 658} 659 | 633 634 /* Clear our MAC address. */ 635 ifa = ifaddr_byindex(ifv->ifv_if.if_index); 636 sdl = (struct sockaddr_dl *)ifa->ifa_addr; 637 sdl->sdl_type = IFT_ETHER; 638 sdl->sdl_alen = ETHER_ADDR_LEN; 639 bzero(LLADDR(sdl), ETHER_ADDR_LEN); 640 bzero(ifv->ifv_ac.ac_enaddr, ETHER_ADDR_LEN); --- 19 unchanged lines hidden (view full) --- 660 if (error == 0) 661 ifv->ifv_flags &= ~IFVF_PROMISC; 662 } 663 } 664 665 return (error); 666} 667 |
668/* Inform all vlans that their parent has changed link state */ 669static void 670vlan_link_state(struct ifnet *ifp, int link) 671{ 672 struct ifvlan *ifv; 673 674 VLAN_LOCK(); 675 LIST_FOREACH(ifv, &ifv_list, ifv_list) { 676 if (ifv->ifv_p == ifp) { 677 ifv->ifv_if.if_link_state = ifv->ifv_p->if_link_state; 678 rt_ifmsg(&(ifv->ifv_if)); 679 KNOTE(&ifp->if_klist, link); 680 } 681 } 682 VLAN_UNLOCK(); 683} 684 |
|
660static int 661vlan_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data) 662{ 663 struct ifaddr *ifa; 664 struct ifnet *p; 665 struct ifreq *ifr; 666 struct ifvlan *ifv; 667 struct vlanreq vlr; --- 147 unchanged lines hidden --- | 685static int 686vlan_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data) 687{ 688 struct ifaddr *ifa; 689 struct ifnet *p; 690 struct ifreq *ifr; 691 struct ifvlan *ifv; 692 struct vlanreq vlr; --- 147 unchanged lines hidden --- |