[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: kernel/1599: Add support for BIOC[GS]HDRCMPLT



Didn't obecian already do this?

http://www.packetninja.net/openbsd/README.etherspoof

Nick


-----Original Message-----
From: Kyle Hargraves [mailto:halogen_(_at_)_nol_(_dot_)_net]
Sent: Monday, January 01, 2001 4:39 PM
To: bugs_(_at_)_cvs_(_dot_)_openbsd_(_dot_)_org
Subject: kernel/1599: Add support for BIOC[GS]HDRCMPLT



>Number:         1599
>Category:       kernel
>Synopsis:       support BIOC[GS]HDRCMPLT ioctls
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bugs
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Mon Jan  1 14:40:01 MST 2001
>Last-Modified:
>Originator:     Kyle Hargraves <halogen_(_at_)_nol_(_dot_)_net>
>Organization:
net
>Release:        2.8
>Environment:
	
	System      : OpenBSD 2.8
	Architecture: OpenBSD.i386
	Machine     : i386
>Description:
NetBSD implemented the BIOC[GS]HDRCMPLT ioctls which allow you to
set the link-layer source address on outgoing packets. The patch
was also brought into FreeBSD. Wanted to go ahead and add support
for us. I believe I got the patch right, but it definitely needs
a once over (twice).
>How-To-Repeat:
n/a
>Fix:
Index: src/sys/net/bpf.c
===================================================================
RCS file: /cvs/src/sys/net/bpf.c,v
retrieving revision 1.22
diff -u -r1.22 bpf.c
--- src/sys/net/bpf.c	2000/06/19 03:00:51	1.22
+++ src/sys/net/bpf.c	2000/12/22 22:13:39
@@ -514,6 +514,9 @@
 		return (EMSGSIZE);
 	}
 
+	if (d->bd_hdrcmplt)
+		dst.sa_family = pseudo_AF_HDRCMPLT;
+
 	s = splsoftnet();
 	error = (*ifp->if_output)(ifp, m, &dst, (struct rtentry *)0);
 	splx(s);
@@ -556,6 +559,8 @@
  *  BIOCGSTATS		Get packet stats.
  *  BIOCIMMEDIATE	Set immediate mode.
  *  BIOCVERSION		Get filter language version.
+ *  BIOCGHDRCMPLT	Get "header already complete" flag
+ *  BIOCSHDRCMPLT	Set "header already complete" flag
  */
 /* ARGSUSED */
 int
@@ -732,6 +737,14 @@
 			bv->bv_minor = BPF_MINOR_VERSION;
 			break;
 		}
+
+	case BIOCGHDRCMPLT:
+		*(u_int *)addr = d->bd_hdrcmplt;
+		break;
+
+	case BIOCSHDRCMPLT:
+		d->bd_hdrcmplt = *(u_int *)addr ? 1 : 0;
+		break;
 
 
 	case FIONBIO:		/* Non-blocking I/O */
Index: src/sys/net/bpf.h
===================================================================
RCS file: /cvs/src/sys/net/bpf.h,v
retrieving revision 1.13
diff -u -r1.13 bpf.h
--- src/sys/net/bpf.h	2000/06/19 03:00:54	1.13
+++ src/sys/net/bpf.h	2000/12/22 22:13:44
@@ -113,6 +113,8 @@
 #define BIOCVERSION	_IOR('B',113, struct bpf_version)
 #define BIOCSRSIG	_IOW('B',114, u_int)
 #define BIOCGRSIG	_IOR('B',115, u_int)
+#define BIOCGHDRCMPLT	_IOR('B',116, u_int)
+#define BIOCSHDRCMPLT	_IOW('B',117, u_int)
 
 /*
  * Structure prepended to each packet.
Index: src/sys/net/bpfdesc.h
===================================================================
RCS file: /cvs/src/sys/net/bpfdesc.h,v
retrieving revision 1.6
diff -u -r1.6 bpfdesc.h
--- src/sys/net/bpfdesc.h	2000/06/19 03:00:54	1.6
+++ src/sys/net/bpfdesc.h	2000/12/22 22:13:47
@@ -75,6 +75,7 @@
 	u_char		bd_promisc;	/* true if listening promiscuously
*/
 	u_char		bd_state;	/* idle, waiting, or timed out */
 	u_char		bd_immediate;	/* true to return on packet arrival
*/
+	int		bd_hdrcmplt;	/* false to fill in src lladdr
automatically */
 	int		bd_async;	/* non-zero if packet reception
should generate signal */
 	int		bd_sig;		/* signal to send upon packet
reception */
 	pid_t		bd_pgid;	/* process or group id for signal */
Index: src/sys/net/if_ethersubr.c
===================================================================
RCS file: /cvs/src/sys/net/if_ethersubr.c,v
retrieving revision 1.39
diff -u -r1.39 if_ethersubr.c
--- src/sys/net/if_ethersubr.c	2000/10/18 16:16:33	1.39
+++ src/sys/net/if_ethersubr.c	2000/12/22 22:14:06
@@ -238,8 +238,8 @@
 	struct rtentry *rt0;
 {
 	u_int16_t etype;
-	int s, error = 0;
- 	u_char edst[6];
+	int s, error = 0, hdrcmplt = 0;
+ 	u_char edst[6], esrc[6];
 	register struct mbuf *m = m0;
 	register struct rtentry *rt;
 	struct mbuf *mcopy = (struct mbuf *)0;
@@ -471,6 +471,12 @@
 #endif /* LLC_DEBUG */
 		} break;
 
+	case pseudo_AF_HDRCMPLT:
+		hdrcmplt = 1;
+		eh = (struct ether_header *)dst->sa_data;
+		bcopy((caddr_t)eh->ether_shost, (caddr_t)esrc, sizeof
(esrc));
+		/* FALLTHROUGH */
+
 	case AF_UNSPEC:
 		eh = (struct ether_header *)dst->sa_data;
  		bcopy((caddr_t)eh->ether_dhost, (caddr_t)edst, sizeof
(edst));
@@ -498,8 +504,12 @@
 	bcopy((caddr_t)&etype,(caddr_t)&eh->ether_type,
 		sizeof(eh->ether_type));
  	bcopy((caddr_t)edst, (caddr_t)eh->ether_dhost, sizeof (edst));
- 	bcopy((caddr_t)ac->ac_enaddr, (caddr_t)eh->ether_shost,
-	    sizeof(eh->ether_shost));
+	if (hdrcmplt)
+	 	bcopy((caddr_t)esrc, (caddr_t)eh->ether_shost,
+		    sizeof(eh->ether_shost));
+	else
+	 	bcopy((caddr_t)ac->ac_enaddr, (caddr_t)eh->ether_shost,
+		    sizeof(eh->ether_shost));
 
 #if NBRIDGE > 0
 	/*
Index: src/sys/net/if_fddisubr.c
===================================================================
RCS file: /cvs/src/sys/net/if_fddisubr.c,v
retrieving revision 1.22
diff -u -r1.22 if_fddisubr.c
--- src/sys/net/if_fddisubr.c	2000/02/07 06:09:08	1.22
+++ src/sys/net/if_fddisubr.c	2000/12/22 22:14:24
@@ -150,8 +150,8 @@
 	struct rtentry *rt0;
 {
 	u_int16_t type;
-	int s, error = 0;
- 	u_char edst[6];
+	int s, error = 0, hdrcmplt = 0;
+ 	u_char edst[6], esrc[6];
 	register struct mbuf *m = m0;
 	register struct rtentry *rt;
 	struct mbuf *mcopy = (struct mbuf *)0;
@@ -339,6 +339,15 @@
 		} break;
 #endif /* CCITT */	
 
+	case pseudo_AF_HDRCMPLT:
+	{
+		struct ether_header *eh;
+		hdrcmplt = 1;
+		eh = (struct ether_header *)dst->sa_data;
+		bcopy((caddr_t)eh->ether_shost, (caddr_t)esrc, sizeof
(esrc));
+		/* FALLTHROUGH */
+	}
+
 	case AF_UNSPEC:
 	{
 		struct ether_header *eh;
@@ -419,8 +428,12 @@
 #if NBPFILTER > 0
   queue_it:
 #endif
- 	bcopy((caddr_t)ac->ac_enaddr, (caddr_t)fh->fddi_shost,
-	    sizeof(fh->fddi_shost));
+	if (hdrcmplt)
+		bcopy((caddr_t)esrc, (caddr_t)fh->fddi_shost,
+		    sizeof(fh->fddi_shost));
+	else
+	 	bcopy((caddr_t)ac->ac_enaddr, (caddr_t)fh->fddi_shost,
+		    sizeof(fh->fddi_shost));
 	s = splimp();
 	/*
 	 * Queue message on interface, and start output if interface

>Audit-Trail:
>Unformatted: