Index: sbin/ifconfig/ifconfig.c =================================================================== RCS file: /cvs/src/sbin/ifconfig/ifconfig.c,v retrieving revision 1.302 diff -u -p -r1.302 ifconfig.c --- sbin/ifconfig/ifconfig.c 3 Oct 2015 10:44:23 -0000 1.302 +++ sbin/ifconfig/ifconfig.c 12 Oct 2015 12:40:00 -0000 @@ -181,6 +181,7 @@ void deletetunnel(const char *, int); void settunnelinst(const char *, int); void settunnelttl(const char *, int); void setvnetid(const char *, int); +void delvnetid(const char *, int); #ifdef INET6 void setia6flags(const char *, int); void setia6pltime(const char *, int); @@ -413,6 +414,7 @@ const struct cmd { { "tunneldomain", NEXTARG, 0, settunnelinst } , { "tunnelttl", NEXTARG, 0, settunnelttl } , { "vnetid", NEXTARG, 0, setvnetid }, + { "-vnetid", 0, 0, delvnetid }, { "pppoedev", NEXTARG, 0, setpppoe_dev }, { "pppoesvc", NEXTARG, 0, setpppoe_svc }, { "-pppoesvc", 1, 0, setpppoe_svc }, @@ -2868,7 +2870,7 @@ phys_status(int force) if (dstport) printf(":%u", ntohs(dstport)); - if (ioctl(s, SIOCGVNETID, (caddr_t)&ifr) == 0 && ifr.ifr_vnetid > 0) + if (ioctl(s, SIOCGVNETID, (caddr_t)&ifr) == 0) printf(" vnetid %d", ifr.ifr_vnetid); if (ioctl(s, SIOCGLIFPHYTTL, (caddr_t)&ifr) == 0 && ifr.ifr_ttl > 0) printf(" ttl %d", ifr.ifr_ttl); @@ -3391,7 +3393,7 @@ void setvnetid(const char *id, int param) { const char *errmsg = NULL; - int vnetid; + u_int32_t vnetid; vnetid = strtonum(id, 0, UINT_MAX, &errmsg); if (errmsg) @@ -3401,6 +3403,14 @@ setvnetid(const char *id, int param) ifr.ifr_vnetid = vnetid; if (ioctl(s, SIOCSVNETID, (caddr_t)&ifr) < 0) warn("SIOCSVNETID"); +} + +/* ARGSUSED */ +void +delvnetid(const char *ignored, int alsoignored) +{ + if (ioctl(s, SIOCDVNETID, &ifr) < 0) + warn("SIOCDVNETID"); } void Index: sys/net/if.h =================================================================== RCS file: /cvs/src/sys/net/if.h,v retrieving revision 1.169 diff -u -p -r1.169 if.h --- sys/net/if.h 5 Oct 2015 15:19:29 -0000 1.169 +++ sys/net/if.h 12 Oct 2015 12:40:00 -0000 @@ -354,6 +354,7 @@ struct ifreq { struct sockaddr ifru_broadaddr; short ifru_flags; int ifru_metric; + uint32_t ifru_vnetid; uint64_t ifru_media; caddr_t ifru_data; } ifr_ifru; @@ -366,7 +367,7 @@ struct ifreq { #define ifr_hardmtu ifr_ifru.ifru_metric /* hardmtu (overload) */ #define ifr_media ifr_ifru.ifru_media /* media options */ #define ifr_rdomainid ifr_ifru.ifru_metric /* VRF instance (overload) */ -#define ifr_vnetid ifr_ifru.ifru_metric /* Virtual Net Id (overload) */ +#define ifr_vnetid ifr_ifru.ifru_vnetid /* Virtual Net Id */ #define ifr_ttl ifr_ifru.ifru_metric /* tunnel TTL (overload) */ #define ifr_data ifr_ifru.ifru_data /* for use by interface */ }; Index: sys/net/if_vxlan.c =================================================================== RCS file: /cvs/src/sys/net/if_vxlan.c,v retrieving revision 1.30 diff -u -p -r1.30 if_vxlan.c --- sys/net/if_vxlan.c 12 Oct 2015 10:51:49 -0000 1.30 +++ sys/net/if_vxlan.c 12 Oct 2015 12:40:00 -0000 @@ -80,7 +80,7 @@ int vxlan_enable = 0; u_long vxlan_tagmask; #define VXLAN_TAGHASHSIZE 32 -#define VXLAN_TAGHASH(tag) (tag & vxlan_tagmask) +#define VXLAN_TAGHASH(tag) ((unsigned int)tag & vxlan_tagmask) LIST_HEAD(vxlan_taghash, vxlan_softc) *vxlan_tagh; void @@ -108,7 +108,7 @@ vxlan_clone_create(struct if_clone *ifc, M_WAITOK|M_ZERO); sc->sc_imo.imo_max_memberships = IP_MIN_MEMBERSHIPS; sc->sc_dstport = htons(VXLAN_PORT); - sc->sc_vnetid = 0; + sc->sc_vnetid = -1; ifp = &sc->sc_ac.ac_if; snprintf(ifp->if_xname, sizeof ifp->if_xname, "vxlan%d", unit); @@ -316,6 +316,12 @@ vxlan_config(struct ifnet *ifp, struct s memcpy(&sc->sc_dst, dst, dst->sa_len); } + memset(&sc->sc_hdr, 0, sizeof(sc->sc_hdr)); + if (sc->sc_vnetid != -1) { + sc->sc_hdr.vxlan_flags = htonl(VXLAN_FLAGS_VNI); + sc->sc_hdr.vxlan_id = htonl(sc->sc_vnetid << VXLAN_VNI_S); + } + LIST_REMOVE(sc, sc_entry); LIST_INSERT_HEAD(&vxlan_tagh[VXLAN_TAGHASH(sc->sc_vnetid)], sc, sc_entry); @@ -420,18 +426,29 @@ vxlanioctl(struct ifnet *ifp, u_long cmd break; case SIOCSVNETID: - if (ifr->ifr_vnetid < 0 || ifr->ifr_vnetid > 0x00ffffff) { + if (ifr->ifr_vnetid > 0x00ffffff) { error = EINVAL; break; } s = splnet(); - sc->sc_vnetid = (u_int32_t)ifr->ifr_vnetid; + sc->sc_vnetid = (int)ifr->ifr_vnetid; (void)vxlan_config(ifp, NULL, NULL); splx(s); break; case SIOCGVNETID: - ifr->ifr_vnetid = (int)sc->sc_vnetid; + if (sc->sc_vnetid == -1) { + error = EADDRNOTAVAIL; + break; + } + ifr->ifr_vnetid = (uint32_t)sc->sc_vnetid; + break; + + case SIOCDVNETID: + s = splnet(); + sc->sc_vnetid = -1; + (void)vxlan_config(ifp, NULL, NULL); + splx(s); break; default: @@ -462,7 +479,7 @@ vxlan_lookup(struct mbuf *m, struct udph struct mbuf_list ml = MBUF_LIST_INITIALIZER(); struct vxlan_softc *sc = NULL, *sc_cand = NULL; struct vxlan_header v; - u_int32_t vni; + int vni = -1; struct ifnet *ifp; int skip; struct ether_header *eh; @@ -479,17 +496,16 @@ vxlan_lookup(struct mbuf *m, struct udph m_copydata(m, skip, sizeof(v), (caddr_t)&v); skip += sizeof(v); - vni = ntohl(v.vxlan_id); - - /* Validate header */ - if ((vni == 0) || (vni & VXLAN_RESERVED2) || - (ntohl(v.vxlan_flags) != VXLAN_FLAGS_VNI)) + if (v.vxlan_flags & htonl(VXLAN_RESERVED1) || + v.vxlan_id & htonl(VXLAN_RESERVED2)) return (0); - vni >>= VXLAN_VNI_S; + if (v.vxlan_flags & htonl(VXLAN_FLAGS_VNI)) + vni = ntohl(v.vxlan_id) >> VXLAN_VNI_S; + LIST_FOREACH(sc, &vxlan_tagh[VXLAN_TAGHASH(vni)], sc_entry) { if ((uh->uh_dport == sc->sc_dstport) && - vni == sc->sc_vnetid && + memcmp(&v, &sc->sc_hdr, sizeof(v)) == 0 && sc->sc_rdomain == rtable_l2(m->m_pkthdr.ph_rtableid)) { sc_cand = sc; switch (srcsa->sa_family) { @@ -615,8 +631,7 @@ vxlan_output(struct ifnet *ifp, struct m #endif vi = (struct vxlanudpiphdr *)ui; - vi->ui_v.vxlan_flags = htonl(VXLAN_FLAGS_VNI); - vi->ui_v.vxlan_id = htonl(sc->sc_vnetid << VXLAN_VNI_S); + memcpy(&vi->ui_v, &sc->sc_hdr, sizeof(vi->ui_v)); /* UDP checksum should be 0 */ ui->ui_sum = 0; Index: sys/net/if_vxlan.h =================================================================== RCS file: /cvs/src/sys/net/if_vxlan.h,v retrieving revision 1.6 diff -u -p -r1.6 if_vxlan.h --- sys/net/if_vxlan.h 19 Dec 2014 17:14:40 -0000 1.6 +++ sys/net/if_vxlan.h 12 Oct 2015 12:40:00 -0000 @@ -53,8 +53,10 @@ struct vxlan_softc { struct sockaddr_storage sc_dst; in_port_t sc_dstport; u_int sc_rdomain; - u_int32_t sc_vnetid; + int sc_vnetid; u_int8_t sc_ttl; + + struct vxlan_header sc_hdr; LIST_ENTRY(vxlan_softc) sc_entry; }; Index: sys/sys/sockio.h =================================================================== RCS file: /cvs/src/sys/sys/sockio.h,v retrieving revision 1.60 diff -u -p -r1.60 sockio.h --- sys/sys/sockio.h 11 Sep 2015 13:02:28 -0000 1.60 +++ sys/sys/sockio.h 12 Oct 2015 12:40:00 -0000 @@ -194,6 +194,8 @@ #define SIOCSETMPWCFG _IOW('i', 173, struct ifreq) /* set mpw config */ #define SIOCGETMPWCFG _IOWR('i', 174, struct ifreq) /* get mpw config */ +#define SIOCDVNETID _IOW('i', 175, struct ifreq) /* del virt net id */ + #define SIOCSVH _IOWR('i', 245, struct ifreq) /* set carp param */ #define SIOCGVH _IOWR('i', 246, struct ifreq) /* get carp param */