if_tap.c (227459) | if_tap.c (236724) |
---|---|
1/*- 2 * Copyright (C) 1999-2000 by Maksim Yevmenkin <m_evmenkin@yahoo.com> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 17 unchanged lines hidden (view full) --- 26 * BASED ON: 27 * ------------------------------------------------------------------------- 28 * 29 * Copyright (c) 1988, Julian Onions <jpo@cs.nott.ac.uk> 30 * Nottingham University 1987. 31 */ 32 33/* | 1/*- 2 * Copyright (C) 1999-2000 by Maksim Yevmenkin <m_evmenkin@yahoo.com> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 17 unchanged lines hidden (view full) --- 26 * BASED ON: 27 * ------------------------------------------------------------------------- 28 * 29 * Copyright (c) 1988, Julian Onions <jpo@cs.nott.ac.uk> 30 * Nottingham University 1987. 31 */ 32 33/* |
34 * $FreeBSD: head/sys/net/if_tap.c 227459 2011-11-11 22:57:52Z brooks $ | 34 * $FreeBSD: head/sys/net/if_tap.c 236724 2012-06-07 19:46:46Z trociny $ |
35 * $Id: if_tap.c,v 0.21 2000/07/23 21:46:02 max Exp $ 36 */ 37 38#include "opt_compat.h" 39#include "opt_inet.h" 40 41#include <sys/param.h> 42#include <sys/conf.h> 43#include <sys/fcntl.h> 44#include <sys/filio.h> | 35 * $Id: if_tap.c,v 0.21 2000/07/23 21:46:02 max Exp $ 36 */ 37 38#include "opt_compat.h" 39#include "opt_inet.h" 40 41#include <sys/param.h> 42#include <sys/conf.h> 43#include <sys/fcntl.h> 44#include <sys/filio.h> |
45#include <sys/jail.h> |
|
45#include <sys/kernel.h> 46#include <sys/malloc.h> 47#include <sys/mbuf.h> 48#include <sys/module.h> 49#include <sys/poll.h> 50#include <sys/priv.h> 51#include <sys/proc.h> 52#include <sys/selinfo.h> --- 8 unchanged lines hidden (view full) --- 61 62#include <net/bpf.h> 63#include <net/ethernet.h> 64#include <net/if.h> 65#include <net/if_clone.h> 66#include <net/if_dl.h> 67#include <net/route.h> 68#include <net/if_types.h> | 46#include <sys/kernel.h> 47#include <sys/malloc.h> 48#include <sys/mbuf.h> 49#include <sys/module.h> 50#include <sys/poll.h> 51#include <sys/priv.h> 52#include <sys/proc.h> 53#include <sys/selinfo.h> --- 8 unchanged lines hidden (view full) --- 62 63#include <net/bpf.h> 64#include <net/ethernet.h> 65#include <net/if.h> 66#include <net/if_clone.h> 67#include <net/if_dl.h> 68#include <net/route.h> 69#include <net/if_types.h> |
70#include <net/vnet.h> |
|
69 70#include <netinet/in.h> 71 72#include <net/if_tapvar.h> 73#include <net/if_tap.h> 74 75 76#define CDEV_NAME "tap" --- 132 unchanged lines hidden (view full) --- 209tap_destroy(struct tap_softc *tp) 210{ 211 struct ifnet *ifp = tp->tap_ifp; 212 213 /* Unlocked read. */ 214 KASSERT(!(tp->tap_flags & TAP_OPEN), 215 ("%s flags is out of sync", ifp->if_xname)); 216 | 71 72#include <netinet/in.h> 73 74#include <net/if_tapvar.h> 75#include <net/if_tap.h> 76 77 78#define CDEV_NAME "tap" --- 132 unchanged lines hidden (view full) --- 211tap_destroy(struct tap_softc *tp) 212{ 213 struct ifnet *ifp = tp->tap_ifp; 214 215 /* Unlocked read. */ 216 KASSERT(!(tp->tap_flags & TAP_OPEN), 217 ("%s flags is out of sync", ifp->if_xname)); 218 |
219 CURVNET_SET(ifp->if_vnet); |
|
217 seldrain(&tp->tap_rsel); 218 knlist_destroy(&tp->tap_rsel.si_note); 219 destroy_dev(tp->tap_dev); 220 ether_ifdetach(ifp); 221 if_free(ifp); 222 223 mtx_destroy(&tp->tap_mtx); 224 free(tp, M_TAP); | 220 seldrain(&tp->tap_rsel); 221 knlist_destroy(&tp->tap_rsel.si_note); 222 destroy_dev(tp->tap_dev); 223 ether_ifdetach(ifp); 224 if_free(ifp); 225 226 mtx_destroy(&tp->tap_mtx); 227 free(tp, M_TAP); |
228 CURVNET_RESTORE(); |
|
225} 226 227static void 228tap_clone_destroy(struct ifnet *ifp) 229{ 230 struct tap_softc *tp = ifp->if_softc; 231 232 mtx_lock(&tapmtx); --- 125 unchanged lines hidden (view full) --- 358 } else { 359 extra = VMNET_DEV_MASK; 360 } 361 } 362 363 if (unit == -1) 364 append_unit = 1; 365 | 229} 230 231static void 232tap_clone_destroy(struct ifnet *ifp) 233{ 234 struct tap_softc *tp = ifp->if_softc; 235 236 mtx_lock(&tapmtx); --- 125 unchanged lines hidden (view full) --- 362 } else { 363 extra = VMNET_DEV_MASK; 364 } 365 } 366 367 if (unit == -1) 368 append_unit = 1; 369 |
370 CURVNET_SET(CRED_TO_VNET(cred)); |
|
366 /* find any existing device, or allocate new unit number */ 367 i = clone_create(&tapclones, &tap_cdevsw, &unit, dev, extra); 368 if (i) { 369 if (append_unit) { 370 /* 371 * We were passed 'tun' or 'tap', with no unit specified 372 * so we'll need to append it now. 373 */ 374 namelen = snprintf(devname, sizeof(devname), "%s%d", name, 375 unit); 376 name = devname; 377 } 378 379 *dev = make_dev_credf(MAKEDEV_REF, &tap_cdevsw, unit | extra, 380 cred, UID_ROOT, GID_WHEEL, 0600, "%s", name); 381 } 382 383 if_clone_create(name, namelen, NULL); | 371 /* find any existing device, or allocate new unit number */ 372 i = clone_create(&tapclones, &tap_cdevsw, &unit, dev, extra); 373 if (i) { 374 if (append_unit) { 375 /* 376 * We were passed 'tun' or 'tap', with no unit specified 377 * so we'll need to append it now. 378 */ 379 namelen = snprintf(devname, sizeof(devname), "%s%d", name, 380 unit); 381 name = devname; 382 } 383 384 *dev = make_dev_credf(MAKEDEV_REF, &tap_cdevsw, unit | extra, 385 cred, UID_ROOT, GID_WHEEL, 0600, "%s", name); 386 } 387 388 if_clone_create(name, namelen, NULL); |
389 CURVNET_RESTORE(); |
|
384} /* tapclone */ 385 386 387/* 388 * tapcreate 389 * 390 * to create interface 391 */ --- 124 unchanged lines hidden (view full) --- 516tapclose(struct cdev *dev, int foo, int bar, struct thread *td) 517{ 518 struct ifaddr *ifa; 519 struct tap_softc *tp = dev->si_drv1; 520 struct ifnet *ifp = tp->tap_ifp; 521 522 /* junk all pending output */ 523 mtx_lock(&tp->tap_mtx); | 390} /* tapclone */ 391 392 393/* 394 * tapcreate 395 * 396 * to create interface 397 */ --- 124 unchanged lines hidden (view full) --- 522tapclose(struct cdev *dev, int foo, int bar, struct thread *td) 523{ 524 struct ifaddr *ifa; 525 struct tap_softc *tp = dev->si_drv1; 526 struct ifnet *ifp = tp->tap_ifp; 527 528 /* junk all pending output */ 529 mtx_lock(&tp->tap_mtx); |
530 CURVNET_SET(ifp->if_vnet); |
|
524 IF_DRAIN(&ifp->if_snd); 525 526 /* 527 * do not bring the interface down, and do not anything with 528 * interface, if we are in VMnet mode. just close the device. 529 */ 530 531 if (((tp->tap_flags & TAP_VMNET) == 0) && (ifp->if_flags & IFF_UP)) { --- 7 unchanged lines hidden (view full) --- 539 rtinit(ifa, (int)RTM_DELETE, 0); 540 } 541 if_purgeaddrs(ifp); 542 mtx_lock(&tp->tap_mtx); 543 } 544 } 545 546 if_link_state_change(ifp, LINK_STATE_DOWN); | 531 IF_DRAIN(&ifp->if_snd); 532 533 /* 534 * do not bring the interface down, and do not anything with 535 * interface, if we are in VMnet mode. just close the device. 536 */ 537 538 if (((tp->tap_flags & TAP_VMNET) == 0) && (ifp->if_flags & IFF_UP)) { --- 7 unchanged lines hidden (view full) --- 546 rtinit(ifa, (int)RTM_DELETE, 0); 547 } 548 if_purgeaddrs(ifp); 549 mtx_lock(&tp->tap_mtx); 550 } 551 } 552 553 if_link_state_change(ifp, LINK_STATE_DOWN); |
554 CURVNET_RESTORE(); 555 |
|
547 funsetown(&tp->tap_sigio); 548 selwakeuppri(&tp->tap_rsel, PZERO+1); 549 KNOTE_LOCKED(&tp->tap_rsel.si_note, 0); 550 551 tp->tap_flags &= ~TAP_OPEN; 552 tp->tap_pid = 0; 553 mtx_unlock(&tp->tap_mtx); 554 --- 385 unchanged lines hidden (view full) --- 940 if (eh && (ifp->if_flags & IFF_PROMISC) == 0 && 941 !ETHER_IS_MULTICAST(eh->ether_dhost) && 942 bcmp(eh->ether_dhost, IF_LLADDR(ifp), ETHER_ADDR_LEN) != 0) { 943 m_freem(m); 944 return (0); 945 } 946 947 /* Pass packet up to parent. */ | 556 funsetown(&tp->tap_sigio); 557 selwakeuppri(&tp->tap_rsel, PZERO+1); 558 KNOTE_LOCKED(&tp->tap_rsel.si_note, 0); 559 560 tp->tap_flags &= ~TAP_OPEN; 561 tp->tap_pid = 0; 562 mtx_unlock(&tp->tap_mtx); 563 --- 385 unchanged lines hidden (view full) --- 949 if (eh && (ifp->if_flags & IFF_PROMISC) == 0 && 950 !ETHER_IS_MULTICAST(eh->ether_dhost) && 951 bcmp(eh->ether_dhost, IF_LLADDR(ifp), ETHER_ADDR_LEN) != 0) { 952 m_freem(m); 953 return (0); 954 } 955 956 /* Pass packet up to parent. */ |
957 CURVNET_SET(ifp->if_vnet); |
|
948 (*ifp->if_input)(ifp, m); | 958 (*ifp->if_input)(ifp, m); |
959 CURVNET_RESTORE(); |
|
949 ifp->if_ipackets ++; /* ibytes are counted in parent */ 950 951 return (0); 952} /* tapwrite */ 953 954 955/* 956 * tappoll --- 129 unchanged lines hidden --- | 960 ifp->if_ipackets ++; /* ibytes are counted in parent */ 961 962 return (0); 963} /* tapwrite */ 964 965 966/* 967 * tappoll --- 129 unchanged lines hidden --- |