if_tun.c (105944) | if_tun.c (106939) |
---|---|
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 105944 2002-10-25 17:31:03Z simokawa $ | 16 * $FreeBSD: head/sys/net/if_tun.c 106939 2002-11-15 00:00:15Z sam $ |
17 */ 18 19#include "opt_inet.h" 20#include "opt_mac.h" 21 22#include <sys/param.h> 23#include <sys/proc.h> 24#include <sys/systm.h> --- 457 unchanged lines hidden (view full) --- 482 */ 483 struct mbuf m; 484 uint32_t af = dst->sa_family; 485 486 m.m_next = m0; 487 m.m_len = 4; 488 m.m_data = (char *)⁡ 489 | 17 */ 18 19#include "opt_inet.h" 20#include "opt_mac.h" 21 22#include <sys/param.h> 23#include <sys/proc.h> 24#include <sys/systm.h> --- 457 unchanged lines hidden (view full) --- 482 */ 483 struct mbuf m; 484 uint32_t af = dst->sa_family; 485 486 m.m_next = m0; 487 m.m_len = 4; 488 m.m_data = (char *)⁡ 489 |
490 bpf_mtap(ifp, &m); | 490 BPF_MTAP(ifp, &m); |
491 } 492 493 /* prepend sockaddr? this may abort if the mbuf allocation fails */ 494 if (tp->tun_flags & TUN_LMODE) { 495 /* allocate space for sockaddr */ 496 M_PREPEND(m0, dst->sa_len, M_DONTWAIT); 497 498 /* if allocation failed drop packet */ --- 268 unchanged lines hidden (view full) --- 767 * Conveniently, we already have a 4-byte address 768 * family prepended to our packet ! 769 * Inconveniently, it's in the wrong byte order ! 770 */ 771 if ((top = m_pullup(top, sizeof(family))) == NULL) 772 return (ENOBUFS); 773 *mtod(top, u_int32_t *) = 774 ntohl(*mtod(top, u_int32_t *)); | 491 } 492 493 /* prepend sockaddr? this may abort if the mbuf allocation fails */ 494 if (tp->tun_flags & TUN_LMODE) { 495 /* allocate space for sockaddr */ 496 M_PREPEND(m0, dst->sa_len, M_DONTWAIT); 497 498 /* if allocation failed drop packet */ --- 268 unchanged lines hidden (view full) --- 767 * Conveniently, we already have a 4-byte address 768 * family prepended to our packet ! 769 * Inconveniently, it's in the wrong byte order ! 770 */ 771 if ((top = m_pullup(top, sizeof(family))) == NULL) 772 return (ENOBUFS); 773 *mtod(top, u_int32_t *) = 774 ntohl(*mtod(top, u_int32_t *)); |
775 bpf_mtap(ifp, top); | 775 BPF_MTAP(ifp, top); |
776 *mtod(top, u_int32_t *) = 777 htonl(*mtod(top, u_int32_t *)); 778 } else { 779 /* 780 * We need to prepend the address family as 781 * a four byte field. Cons up a dummy header 782 * to pacify bpf. This is safe because bpf 783 * will only read from the mbuf (i.e., it won't 784 * try to free it or keep a pointer to it). 785 */ 786 struct mbuf m; 787 uint32_t af = AF_INET; 788 789 m.m_next = top; 790 m.m_len = 4; 791 m.m_data = (char *)⁡ 792 | 776 *mtod(top, u_int32_t *) = 777 htonl(*mtod(top, u_int32_t *)); 778 } else { 779 /* 780 * We need to prepend the address family as 781 * a four byte field. Cons up a dummy header 782 * to pacify bpf. This is safe because bpf 783 * will only read from the mbuf (i.e., it won't 784 * try to free it or keep a pointer to it). 785 */ 786 struct mbuf m; 787 uint32_t af = AF_INET; 788 789 m.m_next = top; 790 m.m_len = 4; 791 m.m_data = (char *)⁡ 792 |
793 bpf_mtap(ifp, &m); | 793 BPF_MTAP(ifp, &m); |
794 } 795 } 796 797 if (tp->tun_flags & TUN_IFHEAD) { 798 if (top->m_len < sizeof(family) && 799 (top = m_pullup(top, sizeof(family))) == NULL) 800 return (ENOBUFS); 801 family = ntohl(*mtod(top, u_int32_t *)); --- 43 unchanged lines hidden --- | 794 } 795 } 796 797 if (tp->tun_flags & TUN_IFHEAD) { 798 if (top->m_len < sizeof(family) && 799 (top = m_pullup(top, sizeof(family))) == NULL) 800 return (ENOBUFS); 801 family = ntohl(*mtod(top, u_int32_t *)); --- 43 unchanged lines hidden --- |