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.10 2004/07/23 07:16:31 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 mbuf *m, uint16_t t); 103 static int vlan_ioctl(struct ifnet *ifp, u_long cmd, caddr_t addr, 104 struct ucred *cr); 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_snd.ifq_maxlen = ifqmaxlen; 233 ether_ifattach(ifp, ifv->ifv_ac.ac_enaddr); 234 /* Now undo some of the damage... */ 235 ifp->if_data.ifi_type = IFT_L2VLAN; 236 ifp->if_data.ifi_hdrlen = EVL_ENCAPLEN; 237 238 return (0); 239 } 240 241 static void 242 vlan_clone_destroy(struct ifnet *ifp) 243 { 244 struct ifvlan *ifv = ifp->if_softc; 245 int s; 246 247 s = splnet(); 248 LIST_REMOVE(ifv, ifv_list); 249 vlan_unconfig(ifp); 250 splx(s); 251 252 ether_ifdetach(ifp); 253 254 free(ifv, M_VLAN); 255 } 256 257 static void 258 vlan_ifinit(void *foo) 259 { 260 return; 261 } 262 263 static void 264 vlan_start(struct ifnet *ifp) 265 { 266 struct ifvlan *ifv; 267 struct ifnet *p; 268 struct ether_vlan_header *evl; 269 struct mbuf *m; 270 271 ifv = ifp->if_softc; 272 p = ifv->ifv_p; 273 274 ifp->if_flags |= IFF_OACTIVE; 275 for (;;) { 276 IF_DEQUEUE(&ifp->if_snd, m); 277 if (m == 0) 278 break; 279 if (ifp->if_bpf) 280 bpf_mtap(ifp, m); 281 282 /* 283 * Do not run parent's if_start() if the parent is not up, 284 * or parent's driver will cause a system crash. 285 */ 286 if ((p->if_flags & (IFF_UP | IFF_RUNNING)) != 287 (IFF_UP | IFF_RUNNING)) { 288 m_freem(m); 289 ifp->if_data.ifi_collisions++; 290 continue; 291 } 292 293 /* 294 * If the LINK0 flag is set, it means the underlying interface 295 * can do VLAN tag insertion itself and doesn't require us to 296 * create a special header for it. In this case, we just pass 297 * the packet along. However, we need some way to tell the 298 * interface where the packet came from so that it knows how 299 * to find the VLAN tag to use, so we set the rcvif in the 300 * mbuf header to our ifnet. 301 * 302 * Note: we also set the M_PROTO1 flag in the mbuf to let 303 * the parent driver know that the rcvif pointer is really 304 * valid. We need to do this because sometimes mbufs will 305 * be allocated by other parts of the system that contain 306 * garbage in the rcvif pointer. Using the M_PROTO1 flag 307 * lets the driver perform a proper sanity check and avoid 308 * following potentially bogus rcvif pointers off into 309 * never-never land. 310 */ 311 if (ifp->if_flags & IFF_LINK0) { 312 m->m_pkthdr.rcvif = ifp; 313 m->m_flags |= M_PROTO1; 314 } else { 315 M_PREPEND(m, EVL_ENCAPLEN, MB_DONTWAIT); 316 if (m == NULL) { 317 printf("%s: M_PREPEND failed", ifp->if_xname); 318 ifp->if_ierrors++; 319 continue; 320 } 321 /* M_PREPEND takes care of m_len, m_pkthdr.len for us */ 322 323 m = m_pullup(m, ETHER_HDR_LEN + EVL_ENCAPLEN); 324 if (m == NULL) { 325 printf("%s: m_pullup failed", ifp->if_xname); 326 ifp->if_ierrors++; 327 continue; 328 } 329 330 /* 331 * Transform the Ethernet header into an Ethernet header 332 * with 802.1Q encapsulation. 333 */ 334 bcopy(mtod(m, char *) + EVL_ENCAPLEN, mtod(m, char *), 335 sizeof(struct ether_header)); 336 evl = mtod(m, struct ether_vlan_header *); 337 evl->evl_proto = evl->evl_encap_proto; 338 evl->evl_encap_proto = htons(ETHERTYPE_VLAN); 339 evl->evl_tag = htons(ifv->ifv_tag); 340 #ifdef DEBUG 341 printf("vlan_start: %*D\n", sizeof *evl, 342 (unsigned char *)evl, ":"); 343 #endif 344 } 345 346 /* 347 * Send it, precisely as ether_output() would have. 348 * We are already running at splimp. 349 */ 350 if (IF_QFULL(&p->if_snd)) { 351 IF_DROP(&p->if_snd); 352 /* XXX stats */ 353 ifp->if_oerrors++; 354 m_freem(m); 355 continue; 356 } 357 IF_ENQUEUE(&p->if_snd, m); 358 ifp->if_opackets++; 359 p->if_obytes += m->m_pkthdr.len; 360 if (m->m_flags & M_MCAST) 361 p->if_omcasts++; 362 if ((p->if_flags & IFF_OACTIVE) == 0) 363 p->if_start(p); 364 } 365 ifp->if_flags &= ~IFF_OACTIVE; 366 367 return; 368 } 369 370 static int 371 vlan_input_tag( struct mbuf *m, uint16_t t) 372 { 373 struct ifvlan *ifv; 374 struct ether_header *eh = mtod(m, struct ether_header *); 375 376 m_adj(m, ETHER_HDR_LEN); 377 378 /* 379 * Fake up a header and send the packet to the physical interface's 380 * bpf tap if active. 381 */ 382 if (m->m_pkthdr.rcvif->if_bpf != NULL) { 383 struct m_hdr mh; 384 struct ether_vlan_header evh; 385 386 bcopy(eh, &evh, 2*ETHER_ADDR_LEN); 387 evh.evl_encap_proto = htons(ETHERTYPE_VLAN); 388 evh.evl_tag = htons(t); 389 evh.evl_proto = eh->ether_type; 390 391 /* This kludge is OK; BPF treats the "mbuf" as read-only */ 392 mh.mh_next = m; 393 mh.mh_data = (char *)&evh; 394 mh.mh_len = ETHER_HDR_LEN + EVL_ENCAPLEN; 395 bpf_mtap(m->m_pkthdr.rcvif, (struct mbuf *)&mh); 396 } 397 398 for (ifv = LIST_FIRST(&ifv_list); ifv != NULL; 399 ifv = LIST_NEXT(ifv, ifv_list)) { 400 if (m->m_pkthdr.rcvif == ifv->ifv_p 401 && ifv->ifv_tag == t) 402 break; 403 } 404 405 if (ifv == NULL || (ifv->ifv_if.if_flags & IFF_UP) == 0) { 406 m_freem(m); 407 return -1; /* So the parent can take note */ 408 } 409 410 /* 411 * Having found a valid vlan interface corresponding to 412 * the given source interface and vlan tag, run the 413 * the real packet through ether_input(). 414 */ 415 m->m_pkthdr.rcvif = &ifv->ifv_if; 416 417 ifv->ifv_if.if_ipackets++; 418 ether_input(&ifv->ifv_if, eh, m); 419 return 0; 420 } 421 422 static int 423 vlan_input(struct ether_header *eh, struct mbuf *m) 424 { 425 struct ifvlan *ifv; 426 427 for (ifv = LIST_FIRST(&ifv_list); ifv != NULL; 428 ifv = LIST_NEXT(ifv, ifv_list)) { 429 if (m->m_pkthdr.rcvif == ifv->ifv_p 430 && (EVL_VLANOFTAG(ntohs(*mtod(m, u_int16_t *))) 431 == ifv->ifv_tag)) 432 break; 433 } 434 435 if (ifv == NULL || (ifv->ifv_if.if_flags & IFF_UP) == 0) { 436 m->m_pkthdr.rcvif->if_noproto++; 437 m_freem(m); 438 return -1; /* so ether_input can take note */ 439 } 440 441 /* 442 * Having found a valid vlan interface corresponding to 443 * the given source interface and vlan tag, remove the 444 * encapsulation, and run the real packet through 445 * ether_input() a second time (it had better be 446 * reentrant!). 447 */ 448 m->m_pkthdr.rcvif = &ifv->ifv_if; 449 eh->ether_type = mtod(m, u_int16_t *)[1]; 450 m->m_data += EVL_ENCAPLEN; 451 m->m_len -= EVL_ENCAPLEN; 452 m->m_pkthdr.len -= EVL_ENCAPLEN; 453 454 ifv->ifv_if.if_ipackets++; 455 ether_input(&ifv->ifv_if, eh, m); 456 return 0; 457 } 458 459 static int 460 vlan_config(struct ifvlan *ifv, struct ifnet *p) 461 { 462 struct ifaddr *ifa1, *ifa2; 463 struct sockaddr_dl *sdl1, *sdl2; 464 465 if (p->if_data.ifi_type != IFT_ETHER) 466 return EPROTONOSUPPORT; 467 if (ifv->ifv_p) 468 return EBUSY; 469 ifv->ifv_p = p; 470 if (p->if_data.ifi_hdrlen == sizeof(struct ether_vlan_header)) 471 ifv->ifv_if.if_mtu = p->if_mtu; 472 else 473 ifv->ifv_if.if_mtu = p->if_data.ifi_mtu - EVL_ENCAPLEN; 474 475 /* 476 * Copy only a selected subset of flags from the parent. 477 * Other flags are none of our business. 478 */ 479 ifv->ifv_if.if_flags = (p->if_flags & 480 (IFF_BROADCAST | IFF_MULTICAST | IFF_SIMPLEX | IFF_POINTOPOINT)); 481 482 /* 483 * Set up our ``Ethernet address'' to reflect the underlying 484 * physical interface's. 485 */ 486 ifa1 = ifnet_addrs[ifv->ifv_if.if_index - 1]; 487 ifa2 = ifnet_addrs[p->if_index - 1]; 488 sdl1 = (struct sockaddr_dl *)ifa1->ifa_addr; 489 sdl2 = (struct sockaddr_dl *)ifa2->ifa_addr; 490 sdl1->sdl_type = IFT_ETHER; 491 sdl1->sdl_alen = ETHER_ADDR_LEN; 492 bcopy(LLADDR(sdl2), LLADDR(sdl1), ETHER_ADDR_LEN); 493 bcopy(LLADDR(sdl2), ifv->ifv_ac.ac_enaddr, ETHER_ADDR_LEN); 494 495 /* 496 * Configure multicast addresses that may already be 497 * joined on the vlan device. 498 */ 499 (void)vlan_setmulti(&ifv->ifv_if); 500 501 return 0; 502 } 503 504 static int 505 vlan_unconfig(struct ifnet *ifp) 506 { 507 struct ifaddr *ifa; 508 struct sockaddr_dl *sdl; 509 struct vlan_mc_entry *mc; 510 struct ifvlan *ifv; 511 struct ifnet *p; 512 int error; 513 514 ifv = ifp->if_softc; 515 p = ifv->ifv_p; 516 517 if (p) { 518 struct sockaddr_dl sdl; 519 520 /* 521 * Since the interface is being unconfigured, we need to 522 * empty the list of multicast groups that we may have joined 523 * while we were alive from the parent's list. 524 */ 525 bzero((char *)&sdl, sizeof sdl); 526 sdl.sdl_len = sizeof sdl; 527 sdl.sdl_family = AF_LINK; 528 sdl.sdl_index = p->if_index; 529 sdl.sdl_type = IFT_ETHER; 530 sdl.sdl_alen = ETHER_ADDR_LEN; 531 532 while(SLIST_FIRST(&ifv->vlan_mc_listhead) != NULL) { 533 mc = SLIST_FIRST(&ifv->vlan_mc_listhead); 534 bcopy((char *)&mc->mc_addr, LLADDR(&sdl), ETHER_ADDR_LEN); 535 error = if_delmulti(p, (struct sockaddr *)&sdl); 536 if (error) 537 return(error); 538 SLIST_REMOVE_HEAD(&ifv->vlan_mc_listhead, mc_entries); 539 free(mc, M_VLAN); 540 } 541 } 542 543 /* Disconnect from parent. */ 544 ifv->ifv_p = NULL; 545 ifv->ifv_if.if_mtu = ETHERMTU; 546 547 /* Clear our MAC address. */ 548 ifa = ifnet_addrs[ifv->ifv_if.if_index - 1]; 549 sdl = (struct sockaddr_dl *)ifa->ifa_addr; 550 sdl->sdl_type = IFT_ETHER; 551 sdl->sdl_alen = ETHER_ADDR_LEN; 552 bzero(LLADDR(sdl), ETHER_ADDR_LEN); 553 bzero(ifv->ifv_ac.ac_enaddr, ETHER_ADDR_LEN); 554 555 return 0; 556 } 557 558 static int 559 vlan_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data, struct ucred *cr) 560 { 561 struct ifaddr *ifa; 562 struct ifnet *p; 563 struct ifreq *ifr; 564 struct ifvlan *ifv; 565 struct vlanreq vlr; 566 int error = 0; 567 568 ifr = (struct ifreq *)data; 569 ifa = (struct ifaddr *)data; 570 ifv = ifp->if_softc; 571 572 switch (cmd) { 573 case SIOCSIFADDR: 574 ifp->if_flags |= IFF_UP; 575 576 switch (ifa->ifa_addr->sa_family) { 577 #ifdef INET 578 case AF_INET: 579 arp_ifinit(&ifv->ifv_if, ifa); 580 break; 581 #endif 582 default: 583 break; 584 } 585 break; 586 587 case SIOCGIFADDR: 588 { 589 struct sockaddr *sa; 590 591 sa = (struct sockaddr *) &ifr->ifr_data; 592 bcopy(((struct arpcom *)ifp->if_softc)->ac_enaddr, 593 (caddr_t) sa->sa_data, ETHER_ADDR_LEN); 594 } 595 break; 596 597 case SIOCGIFMEDIA: 598 if (ifv->ifv_p != NULL) { 599 error = (ifv->ifv_p->if_ioctl)(ifv->ifv_p, 600 SIOCGIFMEDIA, data, cr); 601 /* Limit the result to the parent's current config. */ 602 if (error == 0) { 603 struct ifmediareq *ifmr; 604 605 ifmr = (struct ifmediareq *) data; 606 if (ifmr->ifm_count >= 1 && ifmr->ifm_ulist) { 607 ifmr->ifm_count = 1; 608 error = copyout(&ifmr->ifm_current, 609 ifmr->ifm_ulist, 610 sizeof(int)); 611 } 612 } 613 } else 614 error = EINVAL; 615 break; 616 617 case SIOCSIFMEDIA: 618 error = EINVAL; 619 break; 620 621 case SIOCSIFMTU: 622 /* 623 * Set the interface MTU. 624 * This is bogus. The underlying interface might support 625 * jumbo frames. 626 */ 627 if (ifr->ifr_mtu > ETHERMTU) { 628 error = EINVAL; 629 } else { 630 ifp->if_mtu = ifr->ifr_mtu; 631 } 632 break; 633 634 case SIOCSETVLAN: 635 error = copyin(ifr->ifr_data, &vlr, sizeof vlr); 636 if (error) 637 break; 638 if (vlr.vlr_parent[0] == '\0') { 639 vlan_unconfig(ifp); 640 if (ifp->if_flags & IFF_UP) { 641 int s = splimp(); 642 if_down(ifp); 643 splx(s); 644 } 645 ifp->if_flags &= ~IFF_RUNNING; 646 break; 647 } 648 p = ifunit(vlr.vlr_parent); 649 if (p == 0) { 650 error = ENOENT; 651 break; 652 } 653 error = vlan_config(ifv, p); 654 if (error) 655 break; 656 ifv->ifv_tag = vlr.vlr_tag; 657 ifp->if_flags |= IFF_RUNNING; 658 break; 659 660 case SIOCGETVLAN: 661 bzero(&vlr, sizeof vlr); 662 if (ifv->ifv_p) { 663 strlcpy(vlr.vlr_parent, ifv->ifv_p->if_xname, 664 sizeof(vlr.vlr_parent)); 665 vlr.vlr_tag = ifv->ifv_tag; 666 } 667 error = copyout(&vlr, ifr->ifr_data, sizeof vlr); 668 break; 669 670 case SIOCSIFFLAGS: 671 /* 672 * We don't support promiscuous mode 673 * right now because it would require help from the 674 * underlying drivers, which hasn't been implemented. 675 */ 676 if (ifr->ifr_flags & (IFF_PROMISC)) { 677 ifp->if_flags &= ~(IFF_PROMISC); 678 error = EINVAL; 679 } 680 break; 681 case SIOCADDMULTI: 682 case SIOCDELMULTI: 683 error = vlan_setmulti(ifp); 684 break; 685 default: 686 error = EINVAL; 687 } 688 return error; 689 } 690