summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorhenning <henning@openbsd.org>2014-04-20 15:29:52 +0000
committerhenning <henning@openbsd.org>2014-04-20 15:29:52 +0000
commit4c8595fcb392e472d25d27d49727ea79d4d079cb (patch)
tree55d67db92a3cf6abaa5aee36dd3dc6a843d5989a
parentKNF. (diff)
downloadwireguard-openbsd-4c8595fcb392e472d25d27d49727ea79d4d079cb.tar.xz
wireguard-openbsd-4c8595fcb392e472d25d27d49727ea79d4d079cb.zip
factor our ether_addheader for readability; there's more to come there
ok claudio reyk
-rw-r--r--sys/net/if_ethersubr.c31
1 files changed, 20 insertions, 11 deletions
diff --git a/sys/net/if_ethersubr.c b/sys/net/if_ethersubr.c
index cf0de756f43..6184dde9771 100644
--- a/sys/net/if_ethersubr.c
+++ b/sys/net/if_ethersubr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: if_ethersubr.c,v 1.167 2014/04/20 14:54:39 henning Exp $ */
+/* $OpenBSD: if_ethersubr.c,v 1.168 2014/04/20 15:29:52 henning Exp $ */
/* $NetBSD: if_ethersubr.c,v 1.19 1996/05/07 02:40:30 thorpej Exp $ */
/*
@@ -155,6 +155,9 @@ u_char etherbroadcastaddr[ETHER_ADDR_LEN] =
{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
#define senderr(e) { error = (e); goto bad;}
+static __inline int ether_addheader(struct mbuf **, u_int16_t, u_char *,
+ u_char *);
+
int
ether_ioctl(struct ifnet *ifp, struct arpcom *arp, u_long cmd, caddr_t data)
{
@@ -189,6 +192,21 @@ ether_ioctl(struct ifnet *ifp, struct arpcom *arp, u_long cmd, caddr_t data)
return (error);
}
+static __inline int
+ether_addheader(struct mbuf **m, u_int16_t etype, u_char *esrc, u_char *edst)
+{
+ struct ether_header *eh;
+
+ M_PREPEND(*m, ETHER_HDR_LEN, M_DONTWAIT);
+ if (*m == 0)
+ return (-1);
+ eh = mtod(*m, struct ether_header *);
+ eh->ether_type = etype;
+ memcpy(eh->ether_dhost, edst, sizeof(eh->ether_dhost));
+ memcpy(eh->ether_shost, esrc, sizeof(eh->ether_shost));
+ return (0);
+}
+
/*
* Ethernet output routine.
* Encapsulate a packet of type family for the local net.
@@ -348,17 +366,8 @@ ether_output(struct ifnet *ifp0, struct mbuf *m0, struct sockaddr *dst,
esrc = carp_get_srclladdr(ifp0, esrc);
#endif
- /*
- * Add local net header. If no space in first mbuf,
- * allocate another.
- */
- M_PREPEND(m, ETHER_HDR_LEN, M_DONTWAIT);
- if (m == 0)
+ if (ether_addheader(&m, etype, esrc, edst) == -1)
senderr(ENOBUFS);
- eh = mtod(m, struct ether_header *);
- eh->ether_type = etype;
- memcpy(eh->ether_dhost, edst, sizeof(eh->ether_dhost));
- memcpy(eh->ether_shost, esrc, sizeof(eh->ether_shost));
#if NBRIDGE > 0
/*