if_tun.c (68250) | if_tun.c (69152) |
---|---|
1/* $NetBSD: if_tun.c,v 1.14 1994/06/29 06:36:25 cgd Exp $ */ 2 3/* 4 * Copyright (c) 1988, Julian Onions <jpo@cs.nott.ac.uk> 5 * Nottingham University 1987. 6 * 7 * This source may be freely distributed, however I would be interested 8 * in any changes that are made. 9 * 10 * This driver takes packets off the IP i/f and hands them up to a 11 * user process to have its wicked way with. This driver has it's 12 * roots in a similar driver written by Phil Cockcroft (formerly) at 13 * UCL. This driver is based much more on read/write/poll mode of 14 * operation though. 15 * | 1/* $NetBSD: if_tun.c,v 1.14 1994/06/29 06:36:25 cgd Exp $ */ 2 3/* 4 * Copyright (c) 1988, Julian Onions <jpo@cs.nott.ac.uk> 5 * Nottingham University 1987. 6 * 7 * This source may be freely distributed, however I would be interested 8 * in any changes that are made. 9 * 10 * This driver takes packets off the IP i/f and hands them up to a 11 * user process to have its wicked way with. This driver has it's 12 * roots in a similar driver written by Phil Cockcroft (formerly) at 13 * UCL. This driver is based much more on read/write/poll mode of 14 * operation though. 15 * |
16 * $FreeBSD: head/sys/net/if_tun.c 68250 2000-11-02 16:30:26Z jlemon $ | 16 * $FreeBSD: head/sys/net/if_tun.c 69152 2000-11-25 07:35:38Z jlemon $ |
17 */ 18 19#include "opt_inet.h" 20 21#include <sys/param.h> 22#include <sys/proc.h> 23#include <sys/systm.h> 24#include <sys/mbuf.h> --- 166 unchanged lines hidden (view full) --- 191 dev_t dev; 192 int foo; 193 int bar; 194 struct proc *p; 195{ 196 register int s; 197 struct tun_softc *tp; 198 struct ifnet *ifp; | 17 */ 18 19#include "opt_inet.h" 20 21#include <sys/param.h> 22#include <sys/proc.h> 23#include <sys/systm.h> 24#include <sys/mbuf.h> --- 166 unchanged lines hidden (view full) --- 191 dev_t dev; 192 int foo; 193 int bar; 194 struct proc *p; 195{ 196 register int s; 197 struct tun_softc *tp; 198 struct ifnet *ifp; |
199 struct mbuf *m; | |
200 201 tp = dev->si_drv1; 202 ifp = &tp->tun_if; 203 204 tp->tun_flags &= ~TUN_OPEN; 205 tp->tun_pid = 0; 206 207 /* 208 * junk all pending output 209 */ | 199 200 tp = dev->si_drv1; 201 ifp = &tp->tun_if; 202 203 tp->tun_flags &= ~TUN_OPEN; 204 tp->tun_pid = 0; 205 206 /* 207 * junk all pending output 208 */ |
210 do { 211 s = splimp(); 212 IF_DEQUEUE(&ifp->if_snd, m); 213 splx(s); 214 if (m) 215 m_freem(m); 216 } while (m); | 209 IF_DRAIN(&ifp->if_snd); |
217 218 if (ifp->if_flags & IFF_UP) { 219 s = splimp(); 220 if_down(ifp); 221 splx(s); 222 } 223 224 if (ifp->if_flags & IFF_RUNNING) { --- 107 unchanged lines hidden (view full) --- 332int 333tunoutput(ifp, m0, dst, rt) 334 struct ifnet *ifp; 335 struct mbuf *m0; 336 struct sockaddr *dst; 337 struct rtentry *rt; 338{ 339 struct tun_softc *tp = ifp->if_softc; | 210 211 if (ifp->if_flags & IFF_UP) { 212 s = splimp(); 213 if_down(ifp); 214 splx(s); 215 } 216 217 if (ifp->if_flags & IFF_RUNNING) { --- 107 unchanged lines hidden (view full) --- 325int 326tunoutput(ifp, m0, dst, rt) 327 struct ifnet *ifp; 328 struct mbuf *m0; 329 struct sockaddr *dst; 330 struct rtentry *rt; 331{ 332 struct tun_softc *tp = ifp->if_softc; |
340 int s; | |
341 342 TUNDEBUG ("%s%d: tunoutput\n", ifp->if_name, ifp->if_unit); 343 344 if ((tp->tun_flags & TUN_READY) != TUN_READY) { 345 TUNDEBUG ("%s%d: not ready 0%o\n", ifp->if_name, 346 ifp->if_unit, tp->tun_flags); 347 m_freem (m0); 348 return EHOSTDOWN; --- 26 unchanged lines hidden (view full) --- 375 } 376 377 /* prepend sockaddr? this may abort if the mbuf allocation fails */ 378 if (tp->tun_flags & TUN_LMODE) { 379 /* allocate space for sockaddr */ 380 M_PREPEND(m0, dst->sa_len, M_DONTWAIT); 381 382 /* if allocation failed drop packet */ | 333 334 TUNDEBUG ("%s%d: tunoutput\n", ifp->if_name, ifp->if_unit); 335 336 if ((tp->tun_flags & TUN_READY) != TUN_READY) { 337 TUNDEBUG ("%s%d: not ready 0%o\n", ifp->if_name, 338 ifp->if_unit, tp->tun_flags); 339 m_freem (m0); 340 return EHOSTDOWN; --- 26 unchanged lines hidden (view full) --- 367 } 368 369 /* prepend sockaddr? this may abort if the mbuf allocation fails */ 370 if (tp->tun_flags & TUN_LMODE) { 371 /* allocate space for sockaddr */ 372 M_PREPEND(m0, dst->sa_len, M_DONTWAIT); 373 374 /* if allocation failed drop packet */ |
383 if (m0 == NULL){ 384 s = splimp(); /* spl on queue manipulation */ 385 IF_DROP(&ifp->if_snd); 386 splx(s); | 375 if (m0 == NULL) { 376 ifp->if_iqdrops++; |
387 ifp->if_oerrors++; 388 return (ENOBUFS); 389 } else { 390 bcopy(dst, m0->m_data, dst->sa_len); 391 } 392 } 393 394 if (tp->tun_flags & TUN_IFHEAD) { 395 /* Prepend the address family */ 396 M_PREPEND(m0, 4, M_DONTWAIT); 397 398 /* if allocation failed drop packet */ | 377 ifp->if_oerrors++; 378 return (ENOBUFS); 379 } else { 380 bcopy(dst, m0->m_data, dst->sa_len); 381 } 382 } 383 384 if (tp->tun_flags & TUN_IFHEAD) { 385 /* Prepend the address family */ 386 M_PREPEND(m0, 4, M_DONTWAIT); 387 388 /* if allocation failed drop packet */ |
399 if (m0 == NULL){ 400 s = splimp(); /* spl on queue manipulation */ 401 IF_DROP(&ifp->if_snd); 402 splx(s); | 389 if (m0 == NULL) { 390 ifp->if_iqdrops++; |
403 ifp->if_oerrors++; 404 return ENOBUFS; 405 } else 406 *(u_int32_t *)m0->m_data = htonl(dst->sa_family); 407 } else { 408#ifdef INET 409 if (dst->sa_family != AF_INET) 410#endif 411 { 412 m_freem(m0); 413 return EAFNOSUPPORT; 414 } 415 } 416 | 391 ifp->if_oerrors++; 392 return ENOBUFS; 393 } else 394 *(u_int32_t *)m0->m_data = htonl(dst->sa_family); 395 } else { 396#ifdef INET 397 if (dst->sa_family != AF_INET) 398#endif 399 { 400 m_freem(m0); 401 return EAFNOSUPPORT; 402 } 403 } 404 |
417 s = splimp(); 418 if (IF_QFULL(&ifp->if_snd)) { 419 IF_DROP(&ifp->if_snd); 420 m_freem(m0); 421 splx(s); | 405 if (! IF_HANDOFF(&ifp->if_snd, m0, NULL)) { |
422 ifp->if_collisions++; 423 return ENOBUFS; 424 } | 406 ifp->if_collisions++; 407 return ENOBUFS; 408 } |
425 ifp->if_obytes += m0->m_pkthdr.len; 426 IF_ENQUEUE(&ifp->if_snd, m0); 427 splx(s); | |
428 ifp->if_opackets++; 429 430 if (tp->tun_flags & TUN_RWAIT) { 431 tp->tun_flags &= ~TUN_RWAIT; 432 wakeup((caddr_t)tp); 433 } 434 if (tp->tun_flags & TUN_ASYNC && tp->tun_sigio) 435 pgsigio(tp->tun_sigio, SIGIO, 0); --- 319 unchanged lines hidden --- | 409 ifp->if_opackets++; 410 411 if (tp->tun_flags & TUN_RWAIT) { 412 tp->tun_flags &= ~TUN_RWAIT; 413 wakeup((caddr_t)tp); 414 } 415 if (tp->tun_flags & TUN_ASYNC && tp->tun_sigio) 416 pgsigio(tp->tun_sigio, SIGIO, 0); --- 319 unchanged lines hidden --- |