Deleted Added
full compact
if_tun.c (147256) if_tun.c (147611)
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 147256 2005-06-10 16:49:24Z brooks $
16 * $FreeBSD: head/sys/net/if_tun.c 147611 2005-06-26 18:11:11Z dwmalone $
17 */
18
19#include "opt_atalk.h"
20#include "opt_inet.h"
21#include "opt_inet6.h"
22#include "opt_ipx.h"
23#include "opt_mac.h"
24

--- 255 unchanged lines hidden (view full) ---

280 ifp->if_start = tunstart;
281 ifp->if_flags = IFF_POINTOPOINT | IFF_MULTICAST;
282 ifp->if_softc = sc;
283 IFQ_SET_MAXLEN(&ifp->if_snd, ifqmaxlen);
284 ifp->if_snd.ifq_drv_maxlen = 0;
285 IFQ_SET_READY(&ifp->if_snd);
286
287 if_attach(ifp);
17 */
18
19#include "opt_atalk.h"
20#include "opt_inet.h"
21#include "opt_inet6.h"
22#include "opt_ipx.h"
23#include "opt_mac.h"
24

--- 255 unchanged lines hidden (view full) ---

280 ifp->if_start = tunstart;
281 ifp->if_flags = IFF_POINTOPOINT | IFF_MULTICAST;
282 ifp->if_softc = sc;
283 IFQ_SET_MAXLEN(&ifp->if_snd, ifqmaxlen);
284 ifp->if_snd.ifq_drv_maxlen = 0;
285 IFQ_SET_READY(&ifp->if_snd);
286
287 if_attach(ifp);
288 bpfattach(ifp, DLT_NULL, sizeof(u_int));
288 bpfattach(ifp, DLT_NULL, sizeof(u_int32_t));
289 dev->si_drv1 = sc;
290}
291
292static int
293tunopen(struct cdev *dev, int flag, int mode, struct thread *td)
294{
295 struct ifnet *ifp;
296 struct tun_softc *tp;

--- 171 unchanged lines hidden (view full) ---

468 struct ifnet *ifp,
469 struct mbuf *m0,
470 struct sockaddr *dst,
471 struct rtentry *rt)
472{
473 struct tun_softc *tp = ifp->if_softc;
474 u_short cached_tun_flags;
475 int error;
289 dev->si_drv1 = sc;
290}
291
292static int
293tunopen(struct cdev *dev, int flag, int mode, struct thread *td)
294{
295 struct ifnet *ifp;
296 struct tun_softc *tp;

--- 171 unchanged lines hidden (view full) ---

468 struct ifnet *ifp,
469 struct mbuf *m0,
470 struct sockaddr *dst,
471 struct rtentry *rt)
472{
473 struct tun_softc *tp = ifp->if_softc;
474 u_short cached_tun_flags;
475 int error;
476 u_int32_t af;
476
477 TUNDEBUG (ifp, "tunoutput\n");
478
479#ifdef MAC
480 error = mac_check_ifnet_transmit(ifp, m0);
481 if (error) {
482 m_freem(m0);
483 return (error);

--- 10 unchanged lines hidden (view full) ---

494 return (EHOSTDOWN);
495 }
496
497 if ((ifp->if_flags & IFF_UP) != IFF_UP) {
498 m_freem (m0);
499 return (EHOSTDOWN);
500 }
501
477
478 TUNDEBUG (ifp, "tunoutput\n");
479
480#ifdef MAC
481 error = mac_check_ifnet_transmit(ifp, m0);
482 if (error) {
483 m_freem(m0);
484 return (error);

--- 10 unchanged lines hidden (view full) ---

495 return (EHOSTDOWN);
496 }
497
498 if ((ifp->if_flags & IFF_UP) != IFF_UP) {
499 m_freem (m0);
500 return (EHOSTDOWN);
501 }
502
502 /* BPF write needs to be handled specially */
503 /* BPF writes need to be handled specially. */
503 if (dst->sa_family == AF_UNSPEC) {
504 if (dst->sa_family == AF_UNSPEC) {
504 dst->sa_family = *(mtod(m0, int *));
505 m0->m_len -= sizeof(int);
506 m0->m_pkthdr.len -= sizeof(int);
507 m0->m_data += sizeof(int);
505 bcopy(dst->sa_data, &af, sizeof(af));
506 dst->sa_family = af;
508 }
509
510 if (ifp->if_bpf) {
507 }
508
509 if (ifp->if_bpf) {
511 uint32_t af = dst->sa_family;
510 af = dst->sa_family;
512 bpf_mtap2(ifp->if_bpf, &af, sizeof(af), m0);
513 }
514
515 /* prepend sockaddr? this may abort if the mbuf allocation fails */
516 if (cached_tun_flags & TUN_LMODE) {
517 /* allocate space for sockaddr */
518 M_PREPEND(m0, dst->sa_len, M_DONTWAIT);
519

--- 344 unchanged lines hidden ---
511 bpf_mtap2(ifp->if_bpf, &af, sizeof(af), m0);
512 }
513
514 /* prepend sockaddr? this may abort if the mbuf allocation fails */
515 if (cached_tun_flags & TUN_LMODE) {
516 /* allocate space for sockaddr */
517 M_PREPEND(m0, dst->sa_len, M_DONTWAIT);
518

--- 344 unchanged lines hidden ---