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 9 * supporting documentation, and that the name of M.I.T. not be used 10 * in advertising or publicity pertaining to distribution of the 11 * software without specific, written prior permission. M.I.T. makes 12 * no representations about the suitability of this software for any 13 * purpose. It is provided "as is" without express or implied 14 * warranty. 15 * 16 * THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''. M.I.T. DISCLAIMS 17 * ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE, 18 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT 20 * SHALL M.I.T. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 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: src/sys/net/if_vlan.c,v 1.15.2.13 2003/02/14 22:25:58 fenner Exp $ 30 * $DragonFly: src/sys/net/vlan/if_vlan.c,v 1.7 2004/03/14 15:36:54 joerg Exp $ 31 */ 32 33 /* 34 * if_vlan.c - pseudo-device driver for IEEE 802.1Q virtual LANs. 35 * Might be extended some day to also handle IEEE 802.1p priority 36 * tagging. This is sort of sneaky in the implementation, since 37 * we need to pretend to be enough of an Ethernet implementation 38 * to make arp work. The way we do this is by telling everyone 39 * that we are an Ethernet, and then catch the packets that 40 * ether_output() left on our output queue queue when it calls 41 * if_start(), rewrite them for use by the real outgoing interface, 42 * and ask it to send them. 43 * 44 * 45 * XXX It's incorrect to assume that we must always kludge up 46 * headers on the physical device's behalf: some devices support 47 * VLAN tag insertion and extraction in firmware. For these cases, 48 * one can change the behavior of the vlan interface by setting 49 * the LINK0 flag on it (that is setting the vlan interface's LINK0 50 * flag, _not_ the parent's LINK0 flag; we try to leave the parent 51 * alone). If the interface has the LINK0 flag set, then it will 52 * not modify the ethernet header on output, because the parent 53 * can do that for itself. On input, the parent can call vlan_input_tag() 54 * directly in order to supply us with an incoming mbuf and the vlan 55 * tag value that goes with it. 56 */ 57 58 #ifndef NVLAN 59 #include "use_vlan.h" 60 #endif 61 #include "opt_inet.h" 62 63 #include <sys/param.h> 64 #include <sys/kernel.h> 65 #include <sys/malloc.h> 66 #include <sys/mbuf.h> 67 #include <sys/module.h> 68 #include <sys/queue.h> 69 #include <sys/socket.h> 70 #include <sys/sockio.h> 71 #include <sys/sysctl.h> 72 #include <sys/systm.h> 73 #include <machine/bus.h> /* XXX: Shouldn't really be required! */ 74 75 #include <net/bpf.h> 76 #include <net/ethernet.h> 77 #include <net/if.h> 78 #include <net/if_arp.h> 79 #include <net/if_dl.h> 80 #include <net/if_types.h> 81 #include "if_vlan_var.h" 82 83 #ifdef INET 84 #include <netinet/in.h> 85 #include <netinet/if_ether.h> 86 #endif 87 88 #define VLANNAME "vlan" 89 90 SYSCTL_DECL(_net_link); 91 SYSCTL_NODE(_net_link, IFT_L2VLAN, vlan, CTLFLAG_RW, 0, "IEEE 802.1Q VLAN"); 92 SYSCTL_NODE(_net_link_vlan, PF_LINK, link, CTLFLAG_RW, 0, "for consistency"); 93 94 static MALLOC_DEFINE(M_VLAN, "vlan", "802.1Q Virtual LAN Interface"); 95 static LIST_HEAD(, ifvlan) ifv_list; 96 97 static int vlan_clone_create(struct if_clone *, int); 98 static void vlan_clone_destroy(struct ifnet *); 99 static void vlan_start(struct ifnet *ifp); 100 static void vlan_ifinit(void *foo); 101 static int vlan_input(struct ether_header *eh, struct mbuf *m); 102 static int vlan_input_tag(struct ether_header *eh, struct mbuf *m, 103 u_int16_t t); 104 static int vlan_ioctl(struct ifnet *ifp, u_long cmd, caddr_t addr); 105 static int vlan_setmulti(struct ifnet *ifp); 106 static int vlan_unconfig(struct ifnet *ifp); 107 static int vlan_config(struct ifvlan *ifv, struct ifnet *p); 108 109 struct if_clone vlan_cloner = IF_CLONE_INITIALIZER("vlan", vlan_clone_create, 110 vlan_clone_destroy, NVLAN, IF_MAXUNIT); 111 112 /* 113 * Program our multicast filter. What we're actually doing is 114 * programming the multicast filter of the parent. This has the 115 * side effect of causing the parent interface to receive multicast 116 * traffic that it doesn't really want, which ends up being discarded 117 * later by the upper protocol layers. Unfortunately, there's no way 118 * to avoid this: there really is only one physical interface. 119 */ 120 static int 121 vlan_setmulti(struct ifnet *ifp) 122 { 123 struct ifnet *ifp_p; 124 struct ifmultiaddr *ifma, *rifma = NULL; 125 struct ifvlan *sc; 126 struct vlan_mc_entry *mc = NULL; 127 struct sockaddr_dl sdl; 128 int error; 129 130 /* Find the parent. */ 131 sc = ifp->if_softc; 132 ifp_p = sc->ifv_p; 133 134 /* 135 * If we don't have a parent, just remember the membership for 136 * when we do. 137 */ 138 if (ifp_p == NULL) 139 return(0); 140 141 bzero((char *)&sdl, sizeof sdl); 142 sdl.sdl_len = sizeof sdl; 143 sdl.sdl_family = AF_LINK; 144 sdl.sdl_index = ifp_p->if_index; 145 sdl.sdl_type = IFT_ETHER; 146 sdl.sdl_alen = ETHER_ADDR_LEN; 147 148 /* First, remove any existing filter entries. */ 149 while(SLIST_FIRST(&sc->vlan_mc_listhead) != NULL) { 150 mc = SLIST_FIRST(&sc->vlan_mc_listhead); 151 bcopy((char *)&mc->mc_addr, LLADDR(&sdl), ETHER_ADDR_LEN); 152 error = if_delmulti(ifp_p, (struct sockaddr *)&sdl); 153 if (error) 154 return(error); 155 SLIST_REMOVE_HEAD(&sc->vlan_mc_listhead, mc_entries); 156 free(mc, M_VLAN); 157 } 158 159 /* Now program new ones. */ 160 LIST_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) { 161 if (ifma->ifma_addr->sa_family != AF_LINK) 162 continue; 163 mc = malloc(sizeof(struct vlan_mc_entry), M_VLAN, M_WAITOK); 164 bcopy(LLADDR((struct sockaddr_dl *)ifma->ifma_addr), 165 (char *)&mc->mc_addr, ETHER_ADDR_LEN); 166 SLIST_INSERT_HEAD(&sc->vlan_mc_listhead, mc, mc_entries); 167 bcopy(LLADDR((struct sockaddr_dl *)ifma->ifma_addr), 168 LLADDR(&sdl), ETHER_ADDR_LEN); 169 error = if_addmulti(ifp_p, (struct sockaddr *)&sdl, &rifma); 170 if (error) 171 return(error); 172 } 173 174 return(0); 175 } 176 177 static int 178 vlan_modevent(module_t mod, int type, void *data) 179 { 180 181 switch (type) { 182 case MOD_LOAD: 183 LIST_INIT(&ifv_list); 184 vlan_input_p = vlan_input; 185 vlan_input_tag_p = vlan_input_tag; 186 if_clone_attach(&vlan_cloner); 187 break; 188 case MOD_UNLOAD: 189 if_clone_detach(&vlan_cloner); 190 vlan_input_p = NULL; 191 vlan_input_tag_p = NULL; 192 while (!LIST_EMPTY(&ifv_list)) 193 vlan_clone_destroy(&LIST_FIRST(&ifv_list)->ifv_if); 194 break; 195 } 196 return 0; 197 } 198 199 static moduledata_t vlan_mod = { 200 "if_vlan", 201 vlan_modevent, 202 0 203 }; 204 205 DECLARE_MODULE(if_vlan, vlan_mod, SI_SUB_PSEUDO, SI_ORDER_ANY); 206 207 static int 208 vlan_clone_create(struct if_clone *ifc, int unit) 209 { 210 struct ifvlan *ifv; 211 struct ifnet *ifp; 212 int s; 213 214 ifv = malloc(sizeof(struct ifvlan), M_VLAN, M_WAITOK | M_ZERO); 215 ifp = &ifv->ifv_if; 216 SLIST_INIT(&ifv->vlan_mc_listhead); 217 218 s = splnet(); 219 LIST_INSERT_HEAD(&ifv_list, ifv, ifv_list); 220 splx(s); 221 222 ifp->if_softc = ifv; 223 if_initname(ifp, "vlan", unit); 224 /* NB: flags are not set here */ 225 ifp->if_linkmib = &ifv->ifv_mib; 226 ifp->if_linkmiblen = sizeof ifv->ifv_mib; 227 /* NB: mtu is not set here */ 228 229 ifp->if_init = vlan_ifinit; 230 ifp->if_start = vlan_start; 231 ifp->if_ioctl = vlan_ioctl; 232 ifp->if_output = ether_output; 233 ifp->if_snd.ifq_maxlen = ifqmaxlen; 234 ether_ifattach(ifp, ifv->ifv_ac.ac_enaddr); 235 /* Now undo some of the damage... */ 236 ifp->if_data.ifi_type = IFT_L2VLAN; 237 ifp->if_data.ifi_hdrlen = EVL_ENCAPLEN; 238 239 return (0); 240 } 241 242 static void 243 vlan_clone_destroy(struct ifnet *ifp) 244 { 245 struct ifvlan *ifv = ifp->if_softc; 246 int s; 247 248 s = splnet(); 249 LIST_REMOVE(ifv, ifv_list); 250 vlan_unconfig(ifp); 251 splx(s); 252 253 ether_ifdetach(ifp); 254 255 free(ifv, M_VLAN); 256 } 257 258 static void 259 vlan_ifinit(void *foo) 260 { 261 return; 262 } 263 264 static void 265 vlan_start(struct ifnet *ifp) 266 { 267 struct ifvlan *ifv; 268 struct ifnet *p; 269 struct ether_vlan_header *evl; 270 struct mbuf *m; 271 272 ifv = ifp->if_softc; 273 p = ifv->ifv_p; 274 275 ifp->if_flags |= IFF_OACTIVE; 276 for (;;) { 277 IF_DEQUEUE(&ifp->if_snd, m); 278 if (m == 0) 279 break; 280 if (ifp->if_bpf) 281 bpf_mtap(ifp, m); 282 283 /* 284 * Do not run parent's if_start() if the parent is not up, 285 * or parent's driver will cause a system crash. 286 */ 287 if ((p->if_flags & (IFF_UP | IFF_RUNNING)) != 288 (IFF_UP | IFF_RUNNING)) { 289 m_freem(m); 290 ifp->if_data.ifi_collisions++; 291 continue; 292 } 293 294 /* 295 * If the LINK0 flag is set, it means the underlying interface 296 * can do VLAN tag insertion itself and doesn't require us to 297 * create a special header for it. In this case, we just pass 298 * the packet along. However, we need some way to tell the 299 * interface where the packet came from so that it knows how 300 * to find the VLAN tag to use, so we set the rcvif in the 301 * mbuf header to our ifnet. 302 * 303 * Note: we also set the M_PROTO1 flag in the mbuf to let 304 * the parent driver know that the rcvif pointer is really 305 * valid. We need to do this because sometimes mbufs will 306 * be allocated by other parts of the system that contain 307 * garbage in the rcvif pointer. Using the M_PROTO1 flag 308 * lets the driver perform a proper sanity check and avoid 309 * following potentially bogus rcvif pointers off into 310 * never-never land. 311 */ 312 if (ifp->if_flags & IFF_LINK0) { 313 m->m_pkthdr.rcvif = ifp; 314 m->m_flags |= M_PROTO1; 315 } else { 316 M_PREPEND(m, EVL_ENCAPLEN, M_DONTWAIT); 317 if (m == NULL) { 318 printf("%s: M_PREPEND failed", ifp->if_xname); 319 ifp->if_ierrors++; 320 continue; 321 } 322 /* M_PREPEND takes care of m_len, m_pkthdr.len for us */ 323 324 m = m_pullup(m, ETHER_HDR_LEN + EVL_ENCAPLEN); 325 if (m == NULL) { 326 printf("%s: m_pullup failed", ifp->if_xname); 327 ifp->if_ierrors++; 328 continue; 329 } 330 331 /* 332 * Transform the Ethernet header into an Ethernet header 333 * with 802.1Q encapsulation. 334 */ 335 bcopy(mtod(m, char *) + EVL_ENCAPLEN, mtod(m, char *), 336 sizeof(struct ether_header)); 337 evl = mtod(m, struct ether_vlan_header *); 338 evl->evl_proto = evl->evl_encap_proto; 339 evl->evl_encap_proto = htons(ETHERTYPE_VLAN); 340 evl->evl_tag = htons(ifv->ifv_tag); 341 #ifdef DEBUG 342 printf("vlan_start: %*D\n", sizeof *evl, 343 (unsigned char *)evl, ":"); 344 #endif 345 } 346 347 /* 348 * Send it, precisely as ether_output() would have. 349 * We are already running at splimp. 350 */ 351 if (IF_QFULL(&p->if_snd)) { 352 IF_DROP(&p->if_snd); 353 /* XXX stats */ 354 ifp->if_oerrors++; 355 m_freem(m); 356 continue; 357 } 358 IF_ENQUEUE(&p->if_snd, m); 359 ifp->if_opackets++; 360 p->if_obytes += m->m_pkthdr.len; 361 if (m->m_flags & M_MCAST) 362 p->if_omcasts++; 363 if ((p->if_flags & IFF_OACTIVE) == 0) 364 p->if_start(p); 365 } 366 ifp->if_flags &= ~IFF_OACTIVE; 367 368 return; 369 } 370 371 static int 372 vlan_input_tag(struct ether_header *eh, struct mbuf *m, u_int16_t t) 373 { 374 struct ifvlan *ifv; 375 376 /* 377 * Fake up a header and send the packet to the physical interface's 378 * bpf tap if active. 379 */ 380 if (m->m_pkthdr.rcvif->if_bpf != NULL) { 381 struct m_hdr mh; 382 struct ether_vlan_header evh; 383 384 bcopy(eh, &evh, 2*ETHER_ADDR_LEN); 385 evh.evl_encap_proto = htons(ETHERTYPE_VLAN); 386 evh.evl_tag = htons(t); 387 evh.evl_proto = eh->ether_type; 388 389 /* This kludge is OK; BPF treats the "mbuf" as read-only */ 390 mh.mh_next = m; 391 mh.mh_data = (char *)&evh; 392 mh.mh_len = ETHER_HDR_LEN + EVL_ENCAPLEN; 393 bpf_mtap(m->m_pkthdr.rcvif, (struct mbuf *)&mh); 394 } 395 396 for (ifv = LIST_FIRST(&ifv_list); ifv != NULL; 397 ifv = LIST_NEXT(ifv, ifv_list)) { 398 if (m->m_pkthdr.rcvif == ifv->ifv_p 399 && ifv->ifv_tag == t) 400 break; 401 } 402 403 if (ifv == NULL || (ifv->ifv_if.if_flags & IFF_UP) == 0) { 404 m_freem(m); 405 return -1; /* So the parent can take note */ 406 } 407 408 /* 409 * Having found a valid vlan interface corresponding to 410 * the given source interface and vlan tag, run the 411 * the real packet through ether_input(). 412 */ 413 m->m_pkthdr.rcvif = &ifv->ifv_if; 414 415 ifv->ifv_if.if_ipackets++; 416 ether_input(&ifv->ifv_if, eh, m); 417 return 0; 418 } 419 420 static int 421 vlan_input(struct ether_header *eh, struct mbuf *m) 422 { 423 struct ifvlan *ifv; 424 425 for (ifv = LIST_FIRST(&ifv_list); ifv != NULL; 426 ifv = LIST_NEXT(ifv, ifv_list)) { 427 if (m->m_pkthdr.rcvif == ifv->ifv_p 428 && (EVL_VLANOFTAG(ntohs(*mtod(m, u_int16_t *))) 429 == ifv->ifv_tag)) 430 break; 431 } 432 433 if (ifv == NULL || (ifv->ifv_if.if_flags & IFF_UP) == 0) { 434 m->m_pkthdr.rcvif->if_noproto++; 435 m_freem(m); 436 return -1; /* so ether_input can take note */ 437 } 438 439 /* 440 * Having found a valid vlan interface corresponding to 441 * the given source interface and vlan tag, remove the 442 * encapsulation, and run the real packet through 443 * ether_input() a second time (it had better be 444 * reentrant!). 445 */ 446 m->m_pkthdr.rcvif = &ifv->ifv_if; 447 eh->ether_type = mtod(m, u_int16_t *)[1]; 448 m->m_data += EVL_ENCAPLEN; 449 m->m_len -= EVL_ENCAPLEN; 450 m->m_pkthdr.len -= EVL_ENCAPLEN; 451 452 ifv->ifv_if.if_ipackets++; 453 ether_input(&ifv->ifv_if, eh, m); 454 return 0; 455 } 456 457 static int 458 vlan_config(struct ifvlan *ifv, struct ifnet *p) 459 { 460 struct ifaddr *ifa1, *ifa2; 461 struct sockaddr_dl *sdl1, *sdl2; 462 463 if (p->if_data.ifi_type != IFT_ETHER) 464 return EPROTONOSUPPORT; 465 if (ifv->ifv_p) 466 return EBUSY; 467 ifv->ifv_p = p; 468 if (p->if_data.ifi_hdrlen == sizeof(struct ether_vlan_header)) 469 ifv->ifv_if.if_mtu = p->if_mtu; 470 else 471 ifv->ifv_if.if_mtu = p->if_data.ifi_mtu - EVL_ENCAPLEN; 472 473 /* 474 * Copy only a selected subset of flags from the parent. 475 * Other flags are none of our business. 476 */ 477 ifv->ifv_if.if_flags = (p->if_flags & 478 (IFF_BROADCAST | IFF_MULTICAST | IFF_SIMPLEX | IFF_POINTOPOINT)); 479 480 /* 481 * Set up our ``Ethernet address'' to reflect the underlying 482 * physical interface's. 483 */ 484 ifa1 = ifnet_addrs[ifv->ifv_if.if_index - 1]; 485 ifa2 = ifnet_addrs[p->if_index - 1]; 486 sdl1 = (struct sockaddr_dl *)ifa1->ifa_addr; 487 sdl2 = (struct sockaddr_dl *)ifa2->ifa_addr; 488 sdl1->sdl_type = IFT_ETHER; 489 sdl1->sdl_alen = ETHER_ADDR_LEN; 490 bcopy(LLADDR(sdl2), LLADDR(sdl1), ETHER_ADDR_LEN); 491 bcopy(LLADDR(sdl2), ifv->ifv_ac.ac_enaddr, ETHER_ADDR_LEN); 492 493 /* 494 * Configure multicast addresses that may already be 495 * joined on the vlan device. 496 */ 497 (void)vlan_setmulti(&ifv->ifv_if); 498 499 return 0; 500 } 501 502 static int 503 vlan_unconfig(struct ifnet *ifp) 504 { 505 struct ifaddr *ifa; 506 struct sockaddr_dl *sdl; 507 struct vlan_mc_entry *mc; 508 struct ifvlan *ifv; 509 struct ifnet *p; 510 int error; 511 512 ifv = ifp->if_softc; 513 p = ifv->ifv_p; 514 515 if (p) { 516 struct sockaddr_dl sdl; 517 518 /* 519 * Since the interface is being unconfigured, we need to 520 * empty the list of multicast groups that we may have joined 521 * while we were alive from the parent's list. 522 */ 523 bzero((char *)&sdl, sizeof sdl); 524 sdl.sdl_len = sizeof sdl; 525 sdl.sdl_family = AF_LINK; 526 sdl.sdl_index = p->if_index; 527 sdl.sdl_type = IFT_ETHER; 528 sdl.sdl_alen = ETHER_ADDR_LEN; 529 530 while(SLIST_FIRST(&ifv->vlan_mc_listhead) != NULL) { 531 mc = SLIST_FIRST(&ifv->vlan_mc_listhead); 532 bcopy((char *)&mc->mc_addr, LLADDR(&sdl), ETHER_ADDR_LEN); 533 error = if_delmulti(p, (struct sockaddr *)&sdl); 534 if (error) 535 return(error); 536 SLIST_REMOVE_HEAD(&ifv->vlan_mc_listhead, mc_entries); 537 free(mc, M_VLAN); 538 } 539 } 540 541 /* Disconnect from parent. */ 542 ifv->ifv_p = NULL; 543 ifv->ifv_if.if_mtu = ETHERMTU; 544 545 /* Clear our MAC address. */ 546 ifa = ifnet_addrs[ifv->ifv_if.if_index - 1]; 547 sdl = (struct sockaddr_dl *)ifa->ifa_addr; 548 sdl->sdl_type = IFT_ETHER; 549 sdl->sdl_alen = ETHER_ADDR_LEN; 550 bzero(LLADDR(sdl), ETHER_ADDR_LEN); 551 bzero(ifv->ifv_ac.ac_enaddr, ETHER_ADDR_LEN); 552 553 return 0; 554 } 555 556 static int 557 vlan_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data) 558 { 559 struct ifaddr *ifa; 560 struct ifnet *p; 561 struct ifreq *ifr; 562 struct ifvlan *ifv; 563 struct vlanreq vlr; 564 int error = 0; 565 566 ifr = (struct ifreq *)data; 567 ifa = (struct ifaddr *)data; 568 ifv = ifp->if_softc; 569 570 switch (cmd) { 571 case SIOCSIFADDR: 572 ifp->if_flags |= IFF_UP; 573 574 switch (ifa->ifa_addr->sa_family) { 575 #ifdef INET 576 case AF_INET: 577 arp_ifinit(&ifv->ifv_if, ifa); 578 break; 579 #endif 580 default: 581 break; 582 } 583 break; 584 585 case SIOCGIFADDR: 586 { 587 struct sockaddr *sa; 588 589 sa = (struct sockaddr *) &ifr->ifr_data; 590 bcopy(((struct arpcom *)ifp->if_softc)->ac_enaddr, 591 (caddr_t) sa->sa_data, ETHER_ADDR_LEN); 592 } 593 break; 594 595 case SIOCGIFMEDIA: 596 if (ifv->ifv_p != NULL) { 597 error = (ifv->ifv_p->if_ioctl)(ifv->ifv_p, SIOCGIFMEDIA, data); 598 /* Limit the result to the parent's current config. */ 599 if (error == 0) { 600 struct ifmediareq *ifmr; 601 602 ifmr = (struct ifmediareq *) data; 603 if (ifmr->ifm_count >= 1 && ifmr->ifm_ulist) { 604 ifmr->ifm_count = 1; 605 error = copyout(&ifmr->ifm_current, 606 ifmr->ifm_ulist, 607 sizeof(int)); 608 } 609 } 610 } else 611 error = EINVAL; 612 break; 613 614 case SIOCSIFMEDIA: 615 error = EINVAL; 616 break; 617 618 case SIOCSIFMTU: 619 /* 620 * Set the interface MTU. 621 * This is bogus. The underlying interface might support 622 * jumbo frames. 623 */ 624 if (ifr->ifr_mtu > ETHERMTU) { 625 error = EINVAL; 626 } else { 627 ifp->if_mtu = ifr->ifr_mtu; 628 } 629 break; 630 631 case SIOCSETVLAN: 632 error = copyin(ifr->ifr_data, &vlr, sizeof vlr); 633 if (error) 634 break; 635 if (vlr.vlr_parent[0] == '\0') { 636 vlan_unconfig(ifp); 637 if (ifp->if_flags & IFF_UP) { 638 int s = splimp(); 639 if_down(ifp); 640 splx(s); 641 } 642 ifp->if_flags &= ~IFF_RUNNING; 643 break; 644 } 645 p = ifunit(vlr.vlr_parent); 646 if (p == 0) { 647 error = ENOENT; 648 break; 649 } 650 error = vlan_config(ifv, p); 651 if (error) 652 break; 653 ifv->ifv_tag = vlr.vlr_tag; 654 ifp->if_flags |= IFF_RUNNING; 655 break; 656 657 case SIOCGETVLAN: 658 bzero(&vlr, sizeof vlr); 659 if (ifv->ifv_p) { 660 strlcpy(vlr.vlr_parent, ifv->ifv_p->if_xname, 661 sizeof(vlr.vlr_parent)); 662 vlr.vlr_tag = ifv->ifv_tag; 663 } 664 error = copyout(&vlr, ifr->ifr_data, sizeof vlr); 665 break; 666 667 case SIOCSIFFLAGS: 668 /* 669 * We don't support promiscuous mode 670 * right now because it would require help from the 671 * underlying drivers, which hasn't been implemented. 672 */ 673 if (ifr->ifr_flags & (IFF_PROMISC)) { 674 ifp->if_flags &= ~(IFF_PROMISC); 675 error = EINVAL; 676 } 677 break; 678 case SIOCADDMULTI: 679 case SIOCDELMULTI: 680 error = vlan_setmulti(ifp); 681 break; 682 default: 683 error = EINVAL; 684 } 685 return error; 686 } 687