PERFORCE change 177258 for review
Ana Kukec
anchie at FreeBSD.org
Fri Apr 23 12:04:23 UTC 2010
http://p4web.freebsd.org/@@177258?ac=10
Change 177258 by anchie at anchie_malimis on 2010/04/23 12:03:46
Cleanup: code related to "SEND through rtsock", whitespaces, debug
printfs, copyright.
Affected files ...
.. //depot/projects/soc2009/anchie_send/src/sys/net/route.h#10 edit
.. //depot/projects/soc2009/anchie_send/src/sys/net/rtsock.c#24 edit
.. //depot/projects/soc2009/anchie_send/src/sys/netinet6/ip6_input.c#6 edit
.. //depot/projects/soc2009/anchie_send/src/sys/netinet6/nd6.c#27 edit
.. //depot/projects/soc2009/anchie_send/src/sys/netinet6/nd6_nbr.c#15 edit
.. //depot/projects/soc2009/anchie_send/src/sys/netinet6/send.c#42 edit
.. //depot/projects/soc2009/anchie_send/src/sys/netinet6/send.h#20 edit
Differences ...
==== //depot/projects/soc2009/anchie_send/src/sys/net/route.h#10 (text+ko) ====
@@ -381,7 +381,6 @@
struct ifmultiaddr;
void rt_ieee80211msg(struct ifnet *, int, void *, size_t);
-void rt_securendmsg(struct ifnet *, int, void *, size_t);
void rt_ifannouncemsg(struct ifnet *, int);
void rt_ifmsg(struct ifnet *);
void rt_missmsg(int, struct rt_addrinfo *, int, int);
==== //depot/projects/soc2009/anchie_send/src/sys/net/rtsock.c#24 (text+ko) ====
@@ -64,8 +64,6 @@
#ifdef INET6
#include <netinet6/scope6_var.h>
#endif
-#include <netinet6/send.h>
-#include <netinet6/in6_var.h>
#if defined(INET) || defined(INET6)
#ifdef SCTP
@@ -1234,7 +1232,6 @@
sizeof(ifan->ifan_name));
ifan->ifan_what = what;
}
-
return m;
}
==== //depot/projects/soc2009/anchie_send/src/sys/netinet6/ip6_input.c#6 (text+ko) ====
@@ -104,7 +104,6 @@
#include <netinet6/scope6_var.h>
#include <netinet6/in6_ifattach.h>
#include <netinet6/nd6.h>
-#include <netinet6/send.h>
#ifdef IPSEC
#include <netipsec/ipsec.h>
==== //depot/projects/soc2009/anchie_send/src/sys/netinet6/nd6.c#27 (text+ko) ====
@@ -296,8 +296,6 @@
nd6_option_init(void *opt, int icmp6len, union nd_opts *ndopts)
{
-printf("XXX-AK: nd6.c: nd6_option_init(), icmp6len = %d\n", icmp6len);
-
bzero(ndopts, sizeof(*ndopts));
ndopts->nd_opts_search = (struct nd_opt_hdr *)opt;
ndopts->nd_opts_last
@@ -330,9 +328,7 @@
nd_opt = ndopts->nd_opts_search;
/* make sure nd_opt_len is inside the buffer */
-printf("nd6.c: nd6_option(), nd_opt->nd_opt_len: %d\n", nd_opt->nd_opt_len);
if ((caddr_t)&nd_opt->nd_opt_len >= (caddr_t)ndopts->nd_opts_last) {
-printf("nd_opt->nd_opt_len >= ndopts->nd_opts_last\n");
bzero(ndopts, sizeof(*ndopts));
return NULL;
}
@@ -1995,10 +1991,8 @@
skip = 1;
nd_type = (unsigned short *)(mtag + 1);
/* Use the SEND socket */
- printf("send_sendso_input_hook\n");
- error = send_sendso_input_hook(V_send_so, m, SND_OUT, ip6len);
-
- return error;
+ return (send_sendso_input_hook(V_send_so,
+ m, SND_OUT, ip6len);
}
}
==== //depot/projects/soc2009/anchie_send/src/sys/netinet6/nd6_nbr.c#15 (text+ko) ====
@@ -400,8 +400,6 @@
caddr_t mac;
struct route_in6 ro;
-printf("nd6_ns_output \n");
-
bzero(&ro, sizeof(ro));
if (IN6_IS_ADDR_MULTICAST(taddr6))
==== //depot/projects/soc2009/anchie_send/src/sys/netinet6/send.c#42 (text+ko) ====
@@ -1,5 +1,5 @@
/*-
- * Copyright (c) 2009 Ana Kukec <anchie at freebsd.org>
+ * Copyright (c) 2009-2010 Ana Kukec <anchie at freebsd.org>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -58,146 +58,137 @@
static int
send_output(struct mbuf *m, struct ifnet *ifp, int direction)
{
- struct ip6_hdr *ip6;
- struct sockaddr_in6 dst;
- struct icmp6_hdr *icmp6;
- int icmp6len;
+ struct ip6_hdr *ip6;
+ struct sockaddr_in6 dst;
+ struct icmp6_hdr *icmp6;
+ int icmp6len;
- /*
- * Receive incoming (SEND-protected) or outgoing traffic
- * (SEND-validated) from the SEND user space application.
- * Outgoing packets are sent out using if_output().
- */
+ /*
+ * Receive incoming (SEND-protected) or outgoing traffic
+ * (SEND-validated) from the SEND user space application.
+ * Outgoing packets are sent out using if_output().
+ */
- switch (direction) {
- case SND_IN:
- /* XXX-BZ can there be extension headers? */
- if (m->m_len < (sizeof(struct ip6_hdr) +
- sizeof(struct icmp6_hdr))) {
- m = m_pullup(m, sizeof(struct ip6_hdr) +
- sizeof(struct icmp6_hdr));
- if (!m)
- return (ENOBUFS);
- }
+ switch (direction) {
+ case SND_IN:
+ if (m->m_len < (sizeof(struct ip6_hdr) +
+ sizeof(struct icmp6_hdr))) {
+ m = m_pullup(m, sizeof(struct ip6_hdr) +
+ sizeof(struct icmp6_hdr));
+ if (!m)
+ return (ENOBUFS);
+ }
- /* Before passing off the mbuf record the proper interface. */
- m->m_pkthdr.rcvif = ifp;
+ /* Before passing off the mbuf record the proper interface. */
+ m->m_pkthdr.rcvif = ifp;
- if (m->m_flags & M_PKTHDR)
- icmp6len = m->m_pkthdr.len - sizeof(struct ip6_hdr);
- else
- panic("Doh! not the first mbuf.");
+ if (m->m_flags & M_PKTHDR)
+ icmp6len = m->m_pkthdr.len - sizeof(struct ip6_hdr);
+ else
+ panic("Doh! not the first mbuf.");
- ip6 = mtod(m, struct ip6_hdr *);
- icmp6 = (struct icmp6_hdr *)(ip6 + 1);
+ ip6 = mtod(m, struct ip6_hdr *);
+ icmp6 = (struct icmp6_hdr *)(ip6 + 1);
- /*
- * Output the packet as icmp6.c:incpm6_input() would do.
- * The mbuf is always consumed, so we do not have to
- * care about that.
- */
- switch (icmp6->icmp6_type) {
- case ND_NEIGHBOR_SOLICIT:
- nd6_ns_input(m, sizeof(struct ip6_hdr), icmp6len);
- break;
- case ND_NEIGHBOR_ADVERT:
- nd6_na_input(m, sizeof(struct ip6_hdr), icmp6len);
- break;
- case ND_REDIRECT:
- icmp6_redirect_input(m, sizeof(struct ip6_hdr));
- break;
- case ND_ROUTER_SOLICIT:
- nd6_rs_input(m, sizeof(struct ip6_hdr), icmp6len);
- break;
- case ND_ROUTER_ADVERT:
- nd6_ra_input(m, sizeof(struct ip6_hdr), icmp6len);
- break;
- default:
- printf("%s:%d: icmp6_code=%u\n",
- __func__, __LINE__, icmp6->icmp6_code);
- m_print(m, m->m_pkthdr.len);
- return (ENOSYS);
- }
+ /*
+ * Output the packet as icmp6.c:incpm6_input() would do.
+ * The mbuf is always consumed, so we do not have to
+ * care about that.
+ */
+ switch (icmp6->icmp6_type) {
+ case ND_NEIGHBOR_SOLICIT:
+ nd6_ns_input(m, sizeof(struct ip6_hdr), icmp6len);
+ break;
+ case ND_NEIGHBOR_ADVERT:
+ nd6_na_input(m, sizeof(struct ip6_hdr), icmp6len);
+ break;
+ case ND_REDIRECT:
+ icmp6_redirect_input(m, sizeof(struct ip6_hdr));
+ break;
+ case ND_ROUTER_SOLICIT:
+ nd6_rs_input(m, sizeof(struct ip6_hdr), icmp6len);
+ break;
+ case ND_ROUTER_ADVERT:
+ nd6_ra_input(m, sizeof(struct ip6_hdr), icmp6len);
+ break;
+ default:
+ return (ENOSYS);
+ }
- /*
- * No error returned from nd6_??_input() so the only thing
- * we can do is to pretend that it worked.
- */
- return (0);
+ /*
+ * No error returned from nd6_??_input() so the only thing
+ * we can do is to pretend that it worked.
+ */
+ return (0);
- case SND_OUT:
- if (m->m_len < sizeof(struct ip6_hdr)) {
- m = m_pullup(m, sizeof(struct ip6_hdr));
- if (!m)
- return (ENOBUFS);
- }
- ip6 = mtod(m, struct ip6_hdr *);
- if (IN6_IS_ADDR_MULTICAST(&ip6->ip6_dst))
- m->m_flags |= M_MCAST;
+ case SND_OUT:
+ if (m->m_len < sizeof(struct ip6_hdr)) {
+ m = m_pullup(m, sizeof(struct ip6_hdr));
+ if (!m)
+ return (ENOBUFS);
+ }
+ ip6 = mtod(m, struct ip6_hdr *);
+ if (IN6_IS_ADDR_MULTICAST(&ip6->ip6_dst))
+ m->m_flags |= M_MCAST;
- bzero(&dst, sizeof(dst));
- dst.sin6_family = AF_INET6;
- dst.sin6_len = sizeof(dst);
- dst.sin6_addr = ip6->ip6_dst;
+ zero(&dst, sizeof(dst));
+ dst.sin6_family = AF_INET6;
+ dst.sin6_len = sizeof(dst);
+ dst.sin6_addr = ip6->ip6_dst;
- /*
- * Output the packet as nd6.c:nd6_output_lle() would do.
- * The mbuf is always consumed, so we do not have to care
- * about that.
- */
- return ((*ifp->if_output)(ifp, m, (struct sockaddr *)&dst,
- NULL));
+ /*
+ * Output the packet as nd6.c:nd6_output_lle() would do.
+ * The mbuf is always consumed, so we do not have to care
+ * about that.
+ */
+ return ((*ifp->if_output)(ifp, m, (struct sockaddr *)&dst,
+ NULL));
- default:
- panic("%s: direction must be either SND_IN or SND_OUT.", __func__);
- }
+ default:
+ panic("%s: direction must be either SND_IN or SND_OUT.", __func__);
+ }
}
static int
send_uattach(struct socket *so, int proto, struct thread *td)
{
- printf("send_uattach: proto = %d\n", proto);
- if (V_send_so != NULL)
- return (EEXIST);
+ if (V_send_so != NULL)
+ return (EEXIST);
- /* XXX: Revisit this, hardocoded! This was a hack for PR_ATOMIC. */
- /* so->so_snd.sb_hiwat = 8192; */
+ V_send_so = so;
- V_send_so = so;
-
- return (0);
+ return (0);
}
static int
sosend_rcv(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
- struct mbuf *control, struct thread *td)
+ struct mbuf *control, struct thread *td)
{
- struct ifnet *ifp;
- struct snd_hdr *snd_hdr;
+ struct ifnet *ifp;
+ struct snd_hdr *snd_hdr;
-printf("sosend_rcv, mbuf len: %d \n", m->m_len);
+ snd_hdr = mtod(m, struct snd_hdr *);
- snd_hdr = mtod(m, struct snd_hdr *);
+ struct mbuf *m0;
+ m0 = m_getcl(M_NOWAIT, MT_DATA, M_PKTHDR);
+ if (m0 == NULL) {
+ m_freem(m);
+ return (ENOBUFS);
+ }
+ m_move_pkthdr(m, m0);
- struct mbuf *m0;
- m0 = m_getcl(M_NOWAIT, MT_DATA, M_PKTHDR);
- if (m0 == NULL) {
- m_freem(m);
- return (ENOBUFS);
- }
- m_move_pkthdr(m, m0);
+ ifp = ifnet_byindex_ref(snd_hdr->ifidx);
+ m_adj(m, SEND_HDR_LEN);
+ m_fixhdr(m);
+ if (ifp) {
+ if (send_output(m, ifp, snd_hdr->direction))
+ return (ENOENT);
+ if_rele(ifp);
+ } else
+ return (ENETUNREACH);
- ifp = ifnet_byindex_ref(snd_hdr->ifidx);
- m_adj(m, SEND_HDR_LEN);
- m_fixhdr(m);
- if (ifp) {
- int error = send_output(m, ifp, snd_hdr->direction);
- printf("error: %d\n", error);
- if_rele(ifp);
- return (0);
- } else
- return (ENETUNREACH);
+ return (0);
}
/*
@@ -210,44 +201,38 @@
struct ip6_hdr *ip6;
struct snd_hdr *snd_hdr = NULL;
-printf("send_sendso_input \n");
-
- /*
- * Make sure to clear any possible internally embedded scope before
- * passing the packet to userspace for SeND cryptographic signature
- * validation to succeed.
- */
- ip6 = mtod(m, struct ip6_hdr *);
- in6_clearscope(&ip6->ip6_src);
- in6_clearscope(&ip6->ip6_dst);
-
- len = m_length(m, NULL);
- if (len != msglen)
- printf("XXX-BZ %s: (m)len=%u (ip6)msglen=%d", __func__, len, msglen);
+ /*
+ * Make sure to clear any possible internally embedded scope before
+ * passing the packet to userspace for SeND cryptographic signature
+ * validation to succeed.
+ */
+ ip6 = mtod(m, struct ip6_hdr *);
+ in6_clearscope(&ip6->ip6_src);
+ in6_clearscope(&ip6->ip6_dst);
+
+ len = m_length(m, NULL);
- m = m_prepend(m, SEND_HDR_LEN, M_PKTHDR|M_DONTWAIT);
- if (m == NULL) {
- printf("m_prepend() failed!\n");
- return (ENOBUFS);
- }
- snd_hdr = mtod(m, struct snd_hdr *);
- snd_hdr->direction = direction;
- snd_hdr->ifidx = -1;
+ m = m_prepend(m, SEND_HDR_LEN, M_PKTHDR|M_DONTWAIT);
+ if (m == NULL) {
+ return (ENOBUFS);
+ }
+ snd_hdr = mtod(m, struct snd_hdr *);
+ snd_hdr->direction = direction;
+ snd_hdr->ifidx = -1;
- /*
- * Send incoming or outgoing traffic to the user space either to be
- * protected (outgoing) or validated (incoming) according to rfc3971. */
+ /*
+ * Send incoming or outgoing traffic to the user space either to be
+ * protected (outgoing) or validated (incoming) according to rfc3971.
+ */
- if (s) {
- SOCKBUF_LOCK(&s->so_rcv);
- sbappendrecord_locked(&s->so_rcv, m);
- sorwakeup_locked(s);
- return 0;
- } else {
- m_freem(m);
- return 0;
- }
+ if (s) {
+ SOCKBUF_LOCK(&s->so_rcv);
+ sbappendrecord_locked(&s->so_rcv, m);
+ sorwakeup_locked(s);
+ return (0);
+ }
+ m_freem(m);
return -1;
}
@@ -255,55 +240,56 @@
send_close(struct socket *so)
{
- if (V_send_so)
- V_send_so = NULL;
+ if (V_send_so)
+ V_send_so = NULL;
}
struct pr_usrreqs send_usrreqs = {
- .pru_attach = send_uattach,
- .pru_send = sosend_rcv,
- .pru_detach = send_close
+ .pru_attach = send_uattach,
+ .pru_send = sosend_rcv,
+ .pru_detach = send_close
};
-
struct protosw send_protosw = {
- .pr_type = SOCK_RAW,
- .pr_protocol = IPPROTO_SEND,
- .pr_usrreqs = &send_usrreqs
+ .pr_type = SOCK_RAW,
+ .pr_protocol = IPPROTO_SEND,
+ .pr_usrreqs = &send_usrreqs
};
static int
send_modevent(module_t mod, int type, void *unused)
{
- int error = 0;
+ int error = 0;
- /* Add locking? icmp6.c and nd6.c are maybe using hooks.. */
+ /* Add locking? icmp6.c and nd6.c are maybe using hooks.. */
- switch (type) {
- case MOD_LOAD:
- error = pf_proto_register(PF_INET, &send_protosw);
- if (error != 0)
- break;
- send_sendso_input_hook = send_sendso_input;
- break;
- case MOD_UNLOAD:
- if (V_send_so != NULL)
- return (EINVAL);
- error = pf_proto_unregister(PF_INET, IPPROTO_SEND, SOCK_RAW);
- send_sendso_input_hook = NULL;
- break;
+ switch (type) {
+ case MOD_LOAD:
+ error = pf_proto_register(PF_INET, &send_protosw);
+ if (error != 0)
+ break;
+ send_sendso_input_hook = send_sendso_input;
+ break;
+ case MOD_UNLOAD:
+ if (V_send_so != NULL)
+ return (EINVAL);
+ error = pf_proto_unregister(PF_INET, IPPROTO_SEND, SOCK_RAW);
+ send_sendso_input_hook = NULL;
+ break;
+ default:
+ break;
+ }
- default:
- break;
- }
- return (error);
+ return (error);
}
static moduledata_t sendmod = {
- "send",
- send_modevent,
- 0
+ "send",
+ send_modevent,
+ 0
};
DECLARE_MODULE(send, sendmod, SI_SUB_PROTO_IFATTACHDOMAIN, SI_ORDER_ANY);
+
+
==== //depot/projects/soc2009/anchie_send/src/sys/netinet6/send.h#20 (text+ko) ====
@@ -1,5 +1,5 @@
/*-
- * Copyright (c) 2009 Ana Kukec <anchie at freebsd.org>
+ * Copyright (c) 2009-2010 Ana Kukec <anchie at freebsd.org>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -30,8 +30,8 @@
#define SEND_HDR_LEN sizeof(struct snd_hdr)
struct snd_hdr {
- int direction;
- int ifidx;
+ int direction;
+ int ifidx;
};
extern int (*send_sendso_input_hook)(struct socket *, struct mbuf *, int, int);
More information about the p4-projects
mailing list