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