commit c6a2635304336c45239bf88ed6989d25db0c489c Author: Ryota Ozaki Date: Wed Apr 22 12:30:53 2015 +0900 Remove if_type switches for non-IFT_ETHER cases diff --git a/sys/net/if_vlan.c b/sys/net/if_vlan.c index 1e3f4d7..5b51900 100644 --- a/sys/net/if_vlan.c +++ b/sys/net/if_vlan.c @@ -271,79 +271,73 @@ vlan_config(struct ifvlan *ifv, struct ifnet *p) { struct ifnet *ifp = &ifv->ifv_if; int error; + struct ethercom *ec = (void *) p; if (ifv->ifv_p != NULL) return (EBUSY); - switch (p->if_type) { - case IFT_ETHER: - { - struct ethercom *ec = (void *) p; + if (p->if_type != IFT_ETHER) + return EPROTONOSUPPORT; - ifv->ifv_msw = &vlan_ether_multisw; - ifv->ifv_encaplen = ETHER_VLAN_ENCAP_LEN; - ifv->ifv_mintu = ETHERMIN; + ifv->ifv_msw = &vlan_ether_multisw; + ifv->ifv_encaplen = ETHER_VLAN_ENCAP_LEN; + ifv->ifv_mintu = ETHERMIN; + /* + * If the parent supports the VLAN_MTU capability, + * i.e. can Tx/Rx larger than ETHER_MAX_LEN frames, + * enable it. + */ + if (ec->ec_nvlans++ == 0 && + (ec->ec_capabilities & ETHERCAP_VLAN_MTU) != 0) { /* - * If the parent supports the VLAN_MTU capability, - * i.e. can Tx/Rx larger than ETHER_MAX_LEN frames, - * enable it. + * Enable Tx/Rx of VLAN-sized frames. */ - if (ec->ec_nvlans++ == 0 && - (ec->ec_capabilities & ETHERCAP_VLAN_MTU) != 0) { - /* - * Enable Tx/Rx of VLAN-sized frames. - */ - ec->ec_capenable |= ETHERCAP_VLAN_MTU; - if (p->if_flags & IFF_UP) { - error = if_flags_set(p, p->if_flags); - if (error) { - if (ec->ec_nvlans-- == 1) - ec->ec_capenable &= - ~ETHERCAP_VLAN_MTU; - return (error); - } + ec->ec_capenable |= ETHERCAP_VLAN_MTU; + if (p->if_flags & IFF_UP) { + error = if_flags_set(p, p->if_flags); + if (error) { + if (ec->ec_nvlans-- == 1) + ec->ec_capenable &= + ~ETHERCAP_VLAN_MTU; + return (error); } - ifv->ifv_mtufudge = 0; - } else if ((ec->ec_capabilities & ETHERCAP_VLAN_MTU) == 0) { - /* - * Fudge the MTU by the encapsulation size. This - * makes us incompatible with strictly compliant - * 802.1Q implementations, but allows us to use - * the feature with other NetBSD implementations, - * which might still be useful. - */ - ifv->ifv_mtufudge = ifv->ifv_encaplen; } - - /* - * If the parent interface can do hardware-assisted - * VLAN encapsulation, then propagate its hardware- - * assisted checksumming flags and tcp segmentation - * offload. - */ - if (ec->ec_capabilities & ETHERCAP_VLAN_HWTAGGING) { - ec->ec_capenable |= ETHERCAP_VLAN_HWTAGGING; - ifp->if_capabilities = p->if_capabilities & - (IFCAP_TSOv4 | IFCAP_TSOv6 | - IFCAP_CSUM_IPv4_Tx|IFCAP_CSUM_IPv4_Rx| - IFCAP_CSUM_TCPv4_Tx|IFCAP_CSUM_TCPv4_Rx| - IFCAP_CSUM_UDPv4_Tx|IFCAP_CSUM_UDPv4_Rx| - IFCAP_CSUM_TCPv6_Tx|IFCAP_CSUM_TCPv6_Rx| - IFCAP_CSUM_UDPv6_Tx|IFCAP_CSUM_UDPv6_Rx); - } + ifv->ifv_mtufudge = 0; + } else if ((ec->ec_capabilities & ETHERCAP_VLAN_MTU) == 0) { /* - * We inherit the parent's Ethernet address. + * Fudge the MTU by the encapsulation size. This + * makes us incompatible with strictly compliant + * 802.1Q implementations, but allows us to use + * the feature with other NetBSD implementations, + * which might still be useful. */ - ether_ifattach(ifp, CLLADDR(p->if_sadl)); - ifp->if_hdrlen = sizeof(struct ether_vlan_header); /* XXX? */ - break; - } + ifv->ifv_mtufudge = ifv->ifv_encaplen; + } - default: - return (EPROTONOSUPPORT); + /* + * If the parent interface can do hardware-assisted + * VLAN encapsulation, then propagate its hardware- + * assisted checksumming flags and tcp segmentation + * offload. + */ + if (ec->ec_capabilities & ETHERCAP_VLAN_HWTAGGING) { + ec->ec_capenable |= ETHERCAP_VLAN_HWTAGGING; + ifp->if_capabilities = p->if_capabilities & + (IFCAP_TSOv4 | IFCAP_TSOv6 | + IFCAP_CSUM_IPv4_Tx|IFCAP_CSUM_IPv4_Rx| + IFCAP_CSUM_TCPv4_Tx|IFCAP_CSUM_TCPv4_Rx| + IFCAP_CSUM_UDPv4_Tx|IFCAP_CSUM_UDPv4_Rx| + IFCAP_CSUM_TCPv6_Tx|IFCAP_CSUM_TCPv6_Rx| + IFCAP_CSUM_UDPv6_Tx|IFCAP_CSUM_UDPv6_Rx); } + /* + * We inherit the parent's Ethernet address. + */ + ether_ifattach(ifp, CLLADDR(p->if_sadl)); + ifp->if_hdrlen = sizeof(struct ether_vlan_header); /* XXX? */ + ifv->ifv_p = p; ifv->ifv_if.if_mtu = p->if_mtu - ifv->ifv_mtufudge; ifv->ifv_if.if_flags = p->if_flags & @@ -366,6 +360,7 @@ vlan_unconfig(struct ifnet *ifp) { struct ifvlan *ifv = ifp->if_softc; struct ifnet *p; + struct ethercom *ec; mutex_enter(&ifv_mtx); p = ifv->ifv_p; @@ -382,34 +377,24 @@ vlan_unconfig(struct ifnet *ifp) */ (*ifv->ifv_msw->vmsw_purgemulti)(ifv); + KASSERT(p->if_type == IFT_ETHER); + /* Disconnect from parent. */ - switch (p->if_type) { - case IFT_ETHER: - { - struct ethercom *ec = (void *) p; - - if (ec->ec_nvlans-- == 1) { - /* - * Disable Tx/Rx of VLAN-sized frames. - */ - ec->ec_capenable &= ~ETHERCAP_VLAN_MTU; - if (p->if_flags & IFF_UP) - (void)if_flags_set(p, p->if_flags); - } - - ether_ifdetach(ifp); - /* Restore vlan_ioctl overwritten by ether_ifdetach */ - ifp->if_ioctl = vlan_ioctl; - vlan_reset_linkname(ifp); - break; - } - -#ifdef DIAGNOSTIC - default: - panic("vlan_unconfig: impossible"); -#endif + ec = (struct ethercom *) p; + if (ec->ec_nvlans-- == 1) { + /* + * Disable Tx/Rx of VLAN-sized frames. + */ + ec->ec_capenable &= ~ETHERCAP_VLAN_MTU; + if (p->if_flags & IFF_UP) + (void)if_flags_set(p, p->if_flags); } + ether_ifdetach(ifp); + /* Restore vlan_ioctl overwritten by ether_ifdetach */ + ifp->if_ioctl = vlan_ioctl; + vlan_reset_linkname(ifp); + ifv->ifv_p = NULL; ifv->ifv_if.if_mtu = 0; ifv->ifv_flags = 0; @@ -727,15 +712,8 @@ vlan_start(struct ifnet *ifp) * the address family/header pointer in the pktattr. */ if (ALTQ_IS_ENABLED(&p->if_snd)) { - switch (p->if_type) { - case IFT_ETHER: - altq_etherclassify(&p->if_snd, m, &pktattr); - break; -#ifdef DIAGNOSTIC - default: - panic("vlan_start: impossible (altq)"); -#endif - } + KASSERT(p->if_type == IFT_ETHER); + altq_etherclassify(&p->if_snd, m, &pktattr); } #endif /* ALTQ */ @@ -757,6 +735,7 @@ vlan_start(struct ifnet *ifp) *(u_int *)(mtag + 1) = ifv->ifv_tag; m_tag_prepend(m, mtag); } else { + struct ether_vlan_header *evl; /* * insert the tag ourselves */ @@ -768,59 +747,48 @@ vlan_start(struct ifnet *ifp) continue; } - switch (p->if_type) { - case IFT_ETHER: - { - struct ether_vlan_header *evl; + KASSERT(p->if_type == IFT_ETHER); - if (m->m_len < sizeof(struct ether_vlan_header)) - m = m_pullup(m, - sizeof(struct ether_vlan_header)); - if (m == NULL) { - printf("%s: unable to pullup encap " - "header", ifv->ifv_p->if_xname); - ifp->if_oerrors++; - continue; - } + if (m->m_len < sizeof(struct ether_vlan_header)) + m = m_pullup(m, + sizeof(struct ether_vlan_header)); + if (m == NULL) { + printf("%s: unable to pullup encap " + "header", ifv->ifv_p->if_xname); + ifp->if_oerrors++; + continue; + } - /* - * Transform the Ethernet header into an - * Ethernet header with 802.1Q encapsulation. - */ - memmove(mtod(m, void *), - mtod(m, char *) + ifv->ifv_encaplen, - sizeof(struct ether_header)); - evl = mtod(m, struct ether_vlan_header *); - evl->evl_proto = evl->evl_encap_proto; - evl->evl_encap_proto = htons(ETHERTYPE_VLAN); - evl->evl_tag = htons(ifv->ifv_tag); + /* + * Transform the Ethernet header into an + * Ethernet header with 802.1Q encapsulation. + */ + memmove(mtod(m, void *), + mtod(m, char *) + ifv->ifv_encaplen, + sizeof(struct ether_header)); + evl = mtod(m, struct ether_vlan_header *); + evl->evl_proto = evl->evl_encap_proto; + evl->evl_encap_proto = htons(ETHERTYPE_VLAN); + evl->evl_tag = htons(ifv->ifv_tag); - /* - * To cater for VLAN-aware layer 2 ethernet - * switches which may need to strip the tag - * before forwarding the packet, make sure - * the packet+tag is at least 68 bytes long. - * This is necessary because our parent will - * only pad to 64 bytes (ETHER_MIN_LEN) and - * some switches will not pad by themselves - * after deleting a tag. - */ - if (m->m_pkthdr.len < + /* + * To cater for VLAN-aware layer 2 ethernet + * switches which may need to strip the tag + * before forwarding the packet, make sure + * the packet+tag is at least 68 bytes long. + * This is necessary because our parent will + * only pad to 64 bytes (ETHER_MIN_LEN) and + * some switches will not pad by themselves + * after deleting a tag. + */ + if (m->m_pkthdr.len < + (ETHER_MIN_LEN - ETHER_CRC_LEN + + ETHER_VLAN_ENCAP_LEN)) { + m_copyback(m, m->m_pkthdr.len, (ETHER_MIN_LEN - ETHER_CRC_LEN + - ETHER_VLAN_ENCAP_LEN)) { - m_copyback(m, m->m_pkthdr.len, - (ETHER_MIN_LEN - ETHER_CRC_LEN + - ETHER_VLAN_ENCAP_LEN) - - m->m_pkthdr.len, - vlan_zero_pad_buff); - } - break; - } - -#ifdef DIAGNOSTIC - default: - panic("vlan_start: impossible"); -#endif + ETHER_VLAN_ENCAP_LEN) - + m->m_pkthdr.len, + vlan_zero_pad_buff); } } @@ -865,38 +833,28 @@ vlan_input(struct ifnet *ifp, struct mbuf *m) tag = EVL_VLANOFTAG(*(u_int *)(mtag + 1)); m_tag_delete(m, mtag); } else { - switch (ifp->if_type) { - case IFT_ETHER: - { - struct ether_vlan_header *evl; + struct ether_vlan_header *evl; - if (m->m_len < sizeof(struct ether_vlan_header) && - (m = m_pullup(m, - sizeof(struct ether_vlan_header))) == NULL) { - printf("%s: no memory for VLAN header, " - "dropping packet.\n", ifp->if_xname); - return; - } - evl = mtod(m, struct ether_vlan_header *); - KASSERT(ntohs(evl->evl_encap_proto) == ETHERTYPE_VLAN); + KASSERT(ifp->if_type == IFT_ETHER); - tag = EVL_VLANOFTAG(ntohs(evl->evl_tag)); - - /* - * Restore the original ethertype. We'll remove - * the encapsulation after we've found the vlan - * interface corresponding to the tag. - */ - evl->evl_encap_proto = evl->evl_proto; - break; - } - - default: - tag = (u_int) -1; /* XXX GCC */ -#ifdef DIAGNOSTIC - panic("vlan_input: impossible"); -#endif + if (m->m_len < sizeof(struct ether_vlan_header) && + (m = m_pullup(m, + sizeof(struct ether_vlan_header))) == NULL) { + printf("%s: no memory for VLAN header, " + "dropping packet.\n", ifp->if_xname); + return; } + evl = mtod(m, struct ether_vlan_header *); + KASSERT(ntohs(evl->evl_encap_proto) == ETHERTYPE_VLAN); + + tag = EVL_VLANOFTAG(ntohs(evl->evl_tag)); + + /* + * Restore the original ethertype. We'll remove + * the encapsulation after we've found the vlan + * interface corresponding to the tag. + */ + evl->evl_encap_proto = evl->evl_proto; } for (ifv = LIST_FIRST(&ifv_list); ifv != NULL;