Deleted Added
full compact
if_tun.c (122352) if_tun.c (123922)
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 122352 2003-11-09 09:17:26Z tanimura $
16 * $FreeBSD: head/sys/net/if_tun.c 123922 2003-12-28 03:56:00Z sam $
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

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

451 if (dst->sa_family == AF_UNSPEC) {
452 dst->sa_family = *(mtod(m0, int *));
453 m0->m_len -= sizeof(int);
454 m0->m_pkthdr.len -= sizeof(int);
455 m0->m_data += sizeof(int);
456 }
457
458 if (ifp->if_bpf) {
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

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

451 if (dst->sa_family == AF_UNSPEC) {
452 dst->sa_family = *(mtod(m0, int *));
453 m0->m_len -= sizeof(int);
454 m0->m_pkthdr.len -= sizeof(int);
455 m0->m_data += sizeof(int);
456 }
457
458 if (ifp->if_bpf) {
459 /*
460 * We need to prepend the address family as
461 * a four byte field. Cons up a dummy header
462 * to pacify bpf. This is safe because bpf
463 * will only read from the mbuf (i.e., it won't
464 * try to free it or keep a pointer to it).
465 */
466 struct mbuf m;
467 uint32_t af = dst->sa_family;
459 uint32_t af = dst->sa_family;
468
469 m.m_next = m0;
470 m.m_len = 4;
471 m.m_data = (char *)&af;
472
473 BPF_MTAP(ifp, &m);
460 bpf_mtap2(ifp->if_bpf, &af, sizeof(af), m0);
474 }
475
476 /* prepend sockaddr? this may abort if the mbuf allocation fails */
477 if (tp->tun_flags & TUN_LMODE) {
478 /* allocate space for sockaddr */
479 M_PREPEND(m0, dst->sa_len, M_DONTWAIT);
480
481 /* if allocation failed drop packet */

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

738 }
739
740 top->m_pkthdr.len = tlen;
741 top->m_pkthdr.rcvif = ifp;
742#ifdef MAC
743 mac_create_mbuf_from_ifnet(ifp, top);
744#endif
745
461 }
462
463 /* prepend sockaddr? this may abort if the mbuf allocation fails */
464 if (tp->tun_flags & TUN_LMODE) {
465 /* allocate space for sockaddr */
466 M_PREPEND(m0, dst->sa_len, M_DONTWAIT);
467
468 /* if allocation failed drop packet */

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

725 }
726
727 top->m_pkthdr.len = tlen;
728 top->m_pkthdr.rcvif = ifp;
729#ifdef MAC
730 mac_create_mbuf_from_ifnet(ifp, top);
731#endif
732
746 if (ifp->if_bpf) {
747 if (tp->tun_flags & TUN_IFHEAD) {
748 /*
749 * Conveniently, we already have a 4-byte address
750 * family prepended to our packet !
751 * Inconveniently, it's in the wrong byte order !
752 */
753 if ((top = m_pullup(top, sizeof(family))) == NULL)
754 return (ENOBUFS);
755 *mtod(top, u_int32_t *) =
756 ntohl(*mtod(top, u_int32_t *));
757 BPF_MTAP(ifp, top);
758 *mtod(top, u_int32_t *) =
759 htonl(*mtod(top, u_int32_t *));
760 } else {
761 /*
762 * We need to prepend the address family as
763 * a four byte field. Cons up a dummy header
764 * to pacify bpf. This is safe because bpf
765 * will only read from the mbuf (i.e., it won't
766 * try to free it or keep a pointer to it).
767 */
768 struct mbuf m;
769 uint32_t af = AF_INET;
770
771 m.m_next = top;
772 m.m_len = 4;
773 m.m_data = (char *)&af;
774
775 BPF_MTAP(ifp, &m);
776 }
777 }
778
779 if (tp->tun_flags & TUN_IFHEAD) {
780 if (top->m_len < sizeof(family) &&
781 (top = m_pullup(top, sizeof(family))) == NULL)
782 return (ENOBUFS);
783 family = ntohl(*mtod(top, u_int32_t *));
784 m_adj(top, sizeof(family));
785 } else
786 family = AF_INET;
787
733 if (tp->tun_flags & TUN_IFHEAD) {
734 if (top->m_len < sizeof(family) &&
735 (top = m_pullup(top, sizeof(family))) == NULL)
736 return (ENOBUFS);
737 family = ntohl(*mtod(top, u_int32_t *));
738 m_adj(top, sizeof(family));
739 } else
740 family = AF_INET;
741
742 BPF_MTAP2(ifp, &family, sizeof(family), top);
743
788 switch (family) {
789#ifdef INET
790 case AF_INET:
791 isr = NETISR_IP;
792 break;
793#endif
794#ifdef INET6
795 case AF_INET6:

--- 57 unchanged lines hidden ---
744 switch (family) {
745#ifdef INET
746 case AF_INET:
747 isr = NETISR_IP;
748 break;
749#endif
750#ifdef INET6
751 case AF_INET6:

--- 57 unchanged lines hidden ---