PERFORCE change 178043 for review
Ana Kukec
anchie at FreeBSD.org
Mon May 10 16:17:25 UTC 2010
http://p4web.freebsd.org/@@178043?ac=10
Change 178043 by anchie at anchie_malimis on 2010/05/10 16:16:32
Getting the SEND userland app ready to pack into ports/packages.
The old functionality is preserved in sendd/os-freebsd-netgraph.
In case of the old code (SEND through netgraph), SND_OS_freebsd
code won't be triggered, SND_OS_freebsd-netgraph code will be
triggered instead.
New functionality related to SEND app through the native SEND API
and native SEND socket is in sendd/os-freebsd, and in the rest
of the code that is triggered depending on SND_OS_freebsd variable.
Affected files ...
.. //depot/projects/soc2009/anchie_send/send_0.2/Makefile#2 edit
.. //depot/projects/soc2009/anchie_send/send_0.2/Makefile.config#3 edit
.. //depot/projects/soc2009/anchie_send/send_0.2/cgatool/cgatool.c#2 edit
.. //depot/projects/soc2009/anchie_send/send_0.2/sendd/net.c#28 edit
.. //depot/projects/soc2009/anchie_send/send_0.2/sendd/os-freebsd-netgraph/Makefile#1 add
.. //depot/projects/soc2009/anchie_send/send_0.2/sendd/os-freebsd-netgraph/addr.c#1 add
.. //depot/projects/soc2009/anchie_send/send_0.2/sendd/os-freebsd-netgraph/netgraph.c#1 add
.. //depot/projects/soc2009/anchie_send/send_0.2/sendd/os-freebsd-netgraph/os_defines.h#1 add
.. //depot/projects/soc2009/anchie_send/send_0.2/sendd/os-freebsd-netgraph/sendd#1 add
.. //depot/projects/soc2009/anchie_send/send_0.2/sendd/os-freebsd-netgraph/snd_freebsd.c#1 add
.. //depot/projects/soc2009/anchie_send/send_0.2/sendd/os-freebsd-netgraph/snd_freebsd.h#1 add
.. //depot/projects/soc2009/anchie_send/send_0.2/sendd/os-freebsd/Makefile#3 edit
.. //depot/projects/soc2009/anchie_send/send_0.2/sendd/os-freebsd/netgraph.c#3 delete
.. //depot/projects/soc2009/anchie_send/send_0.2/sendd/os-freebsd/snd_freebsd.c#4 edit
.. //depot/projects/soc2009/anchie_send/send_0.2/sendd/os-freebsd/snd_freebsd.h#3 edit
.. //depot/projects/soc2009/anchie_send/send_0.2/sendd/proto.c#13 edit
.. //depot/projects/soc2009/anchie_send/send_0.2/sendd/sendd.c#12 edit
.. //depot/projects/soc2009/anchie_send/send_0.2/sendd/sendd_local.h#5 edit
Differences ...
==== //depot/projects/soc2009/anchie_send/send_0.2/Makefile#2 (text+ko) ====
==== //depot/projects/soc2009/anchie_send/send_0.2/Makefile.config#3 (text+ko) ====
@@ -5,6 +5,7 @@
# Uncomment the line for your OS
#OS=linux
+#OS=freebsd-netgraph
OS=freebsd
# Linux only: Where is your linux kernel source?
==== //depot/projects/soc2009/anchie_send/send_0.2/cgatool/cgatool.c#2 (text+ko) ====
@@ -902,7 +902,7 @@
}
static int
-do_select(int cfd)
+do_select_cgatool(int cfd)
{
fd_set fds[1];
@@ -1243,7 +1243,7 @@
return (1);
}
- c = do_select(0);
+ c = do_select_cgatool(0);
#endif
exit(c);
}
==== //depot/projects/soc2009/anchie_send/send_0.2/sendd/net.c#28 (text+ko) ====
@@ -60,7 +60,9 @@
#include <sbuff.h>
static int icmp6sock = -1;
+#ifdef SND_OS_freebsd
static int sndsock = -1;
+#endif
#ifdef DEBUG
static struct dlog_desc dbg = {
@@ -70,6 +72,7 @@
static char abuf[INET6_ADDRSTRLEN];
#endif
+#ifdef SND_OS_freebsd
/* Per-interface info */
struct snd_ifinfo {
struct list_head list;
@@ -82,14 +85,12 @@
/* Data packet meta data */
struct snd_packet_info {
struct snd_ifinfo *ifinfo;
- u_char rtm_version;
- u_char rtm_type;
- int rtm_seq;
int in;
int ifidx;
};
void snd_sock_read(struct snd_ifinfo *p);
+#endif
/* TODO: dynamically size according to MTU */
struct sbuff *
@@ -97,14 +98,14 @@
{
struct sbuff *b;
- /* 2048 + rt_msghdr */
- if ((b = sbuff_alloc(SND_MAX_PKT + sizeof(struct rt_msghdr))) == NULL) {
+ if ((b = sbuff_alloc(SND_MAX_PKT)) == NULL) {
APPLOG_NOMEM();
return (NULL);
}
return (b);
}
+#ifdef SND_MAX_PKT
void
snd_dispatch_fds(fd_set *fds)
{
@@ -143,7 +144,6 @@
snd_deliver_pkt(void *p, struct sbuff *b, int drop, int changed)
{
struct snd_packet_info *pi;
- struct rt_msghdr *rtm;
struct snd_hdr *snd_hdr;
if (drop) {
@@ -152,40 +152,6 @@
}
pi = (struct snd_packet_info *)(b->head);
-
-#if 0
- DBG(&dbg_snd, "Direction, %s", (pi->rtm_seq == RTM_SND_OUT) ? "SND_OUT" : "SND_IN");
-
- /* buffer starts with IPv6 hdr, roll back to include rtm header */
- b->data -= sizeof (struct rt_msghdr);
- b->len += sizeof (struct rt_msghdr);
- //b->data -= sizeof (struct if_announcemsghdr);
- //b->len += sizeof (struct if_announcemsghdr);
-
- DBG(&dbg_snd, "%d bytes on %s", b->len, pi->ifinfo->name);
-
- rtm = sbuff_data(b);
-
- /* reusing RTM header received from kernel */
- rtm->rtm_msglen = b->len;
- rtm->rtm_version = pi->rtm_version;
- rtm->rtm_type = pi->rtm_type;
- rtm->rtm_index = pi->ifinfo->ifidx;
- rtm->rtm_seq = pi->rtm_seq;
- rtm->rtm_pid = getpid();
- rtm->rtm_addrs = 0;
-
- if (rtm->rtm_flags & M_MCAST)
- DBG(&dbg_snd, "M_MCAST!");
-
- if (send(sndsock, b->data, b->len, 0) < 0) {
- DBG(&dbg_snd, "Failed to send routing message back to kernel.");
- perror("Failed");
- snd_put_buf(b);
- return;
- }
-#endif
-
b->data -= SEND_HDR_LEN;
b->len += SEND_HDR_LEN;
snd_hdr = sbuff_data(b);
@@ -204,6 +170,7 @@
return;
}
+
void
snd_add_fds(fd_set *fds, int *maxfd, int sock)
{
@@ -215,6 +182,7 @@
FD_SET(p->snds, fds);
}
}
+#endif
int
freebsd_snd_init(void)
@@ -269,13 +237,12 @@
return (0);
}
+#ifdef SND_OS_freebsd
void
snd_sock_read(struct snd_ifinfo *p)
{
struct snd_hdr *snd_hdr;
int direction;
- struct rt_msghdr *rtm;
- struct if_announcemsghdr *ifan;
struct sbuff *b;
struct snd_packet_info *pi;
int n;
@@ -315,60 +282,11 @@
applog(LOG_ERR, "Unknown SEND pkt header: unknown direction.");
}
-#if 0
- rtm = sbuff_data(b);
- if (rtm->rtm_version != RTM_VERSION) {
- applog(LOG_ERR, "%s: Unsupported routing message version.", __FUNCTION__);
- goto done;
- }
-
- switch (rtm->rtm_type) {
- case RTM_IFANNOUNCE:
- /* XXX: Do we need this? */
- DBG(&dbg_snd, "RTM_IFANNOUNCE");
- break;
- case RTM_SND:
- ifan = (struct if_announcemsghdr *)rtm;
- pi->rtm_version = ifan->ifan_version;
- pi->rtm_type = ifan->ifan_type;
- pi->rtm_seq = ifan->ifan_what;
-
- switch (ifan->ifan_what) {
- case RTM_SND_IN:
- applog(LOG_ERR, "RTM_SND_IN");
- /* n = RTM hdr + SEND message */
- if (sbuff_pull(b, sizeof (struct if_announcemsghdr)) == NULL) {
- DBG(&dbg_snd, "invalid pkt (not enough for rtm hedaer");
- goto done;
- }
- pi->ifinfo = p;
- pi->in = 1;
- snd_recv_pkt(b, p->ifidx, SND_IN, pi);
- break;
-
- case RTM_SND_OUT:
- applog(LOG_ERR, "RTM_SND_OUT");
- /* n = RTM hdr + ip6_hdr + icmp6len */
- if (sbuff_pull(b, sizeof (struct if_announcemsghdr)) == NULL) {
- DBG(&dbg_snd, "invalid pkt (not enough for rtm header");
- goto done;
- }
- pi->ifinfo = p;
- pi->in = 0;
- snd_recv_pkt(b, p->ifidx, SND_OUT, pi);
- break;
- }
- break;
- default:
- applog(LOG_ERR, "%s: Unsupported routing message type.", __FUNCTION__);
- goto done;
- }
-#endif
-
done:
/* ToDo: Free memory! */
snd_put_buf(b);
}
+#endif
/*
* TODO: Linux is not yet up-to-date with rfc3542, specifically in that
@@ -429,9 +347,13 @@
}
int
+#ifdef SND_OS_freebsd
snd_net_init(int *icmp6socket, int *sndsocket)
+#else
+snd_net_init(void)
+#endif
{
- int v, off;
+ int v;
struct icmp6_filter filter;
#ifdef DEBUG
struct dlog_desc *dbgs[] = {
@@ -443,8 +365,11 @@
return (-1);
}
#endif
+#ifdef SND_OS_freebsd
#define IPPROTO_SEND 259
+#endif
+#ifdef SND_OS_freebsd
if ((*sndsocket = socket(PF_INET, SOCK_RAW, IPPROTO_SEND)) < 0) {
applog(LOG_ERR, "%s: socket: %s", __FUNCTION__,
strerror(errno));
@@ -452,25 +377,16 @@
} else {
applog(LOG_ERR, "%s: SEND socket created.", __FUNCTION__);
}
-
+#endif
if ((*icmp6socket = socket(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6)) < 0) {
applog(LOG_ERR, "%s: socket: %s", __FUNCTION__,
strerror(errno));
return (-1);
}
-#if 0
- if ((*sndsocket = socket(PF_ROUTE, SOCK_RAW, 0)) < 0) {
- applog(LOG_ERR, "%s: socket: %s", __FUNCTION__,
- strerror(errno));
- return(-1);
- } else {
- applog(LOG_ERR, "%s: routing socket created.", __FUNCTION__);
- }
-#endif
-
+#ifdef SND_OS_freebsd
icmp6sock = *icmp6socket;
sndsock = *sndsocket;
-
+#endif
v = 255;
if (setsockopt(icmp6sock, IPPROTO_IPV6, IPV6_UNICAST_HOPS, &v,
sizeof (v)) < 0) {
@@ -486,14 +402,6 @@
return (-1);
}
- /* Tell the kernel to not send us back our own rt messages. */
- off = 0;
- if (setsockopt(sndsock, SOL_SOCKET, SO_USELOOPBACK, &off, sizeof(off)) < 0) {
- applog(LOG_ERR, "%s: setsock(sndsock, SO_USELOOPBACK, off) "
- "failed: %s.", __func__, strerror(errno));
- return(-1);
- }
-
ICMP6_FILTER_SETBLOCKALL(&filter);
ICMP6_FILTER_SETPASS(ICMP6_SND_CPS, &filter);
ICMP6_FILTER_SETPASS(ICMP6_SND_CPA, &filter);
@@ -506,5 +414,9 @@
return (-1);
}
+#ifdef SND_OS_freebsd
return (0);
+#else
+ return(icmp6sock);
+#endif
}
==== //depot/projects/soc2009/anchie_send/send_0.2/sendd/os-freebsd/Makefile#3 (text+ko) ====
@@ -1,8 +1,8 @@
-OBJS += os/addr.o os/snd_freebsd.o os/netgraph.o os-linux/rand.o
+OBJS += os/addr.o os/snd_freebsd.o os-linux/rand.o
CPPFLAGS += -I/usr/local/include
-OSLIBS= -lnetgraph -L/usr/local/lib -l$(DNET)
+OSLIBS= -L/usr/local/lib -l$(DNET)
OSEXTRA= os/sendd
EXTRAINSTALL= /etc/rc.d/sendd
==== //depot/projects/soc2009/anchie_send/send_0.2/sendd/os-freebsd/snd_freebsd.c#4 (text+ko) ====
@@ -44,9 +44,6 @@
os_specific_init(void)
{
if (linux_rand_init() < 0 || freebsd_snd_init() < 0) {
-#if 0
- freebsd_netgraph_init() < 0) {
-#endif
return (-1);
}
return (0);
@@ -55,8 +52,5 @@
void
os_specific_fini(void)
{
-#if 0
- freebsd_netgraph_fini();
-#endif
linux_rand_fini();
}
==== //depot/projects/soc2009/anchie_send/send_0.2/sendd/os-freebsd/snd_freebsd.h#3 (text+ko) ====
@@ -37,7 +37,5 @@
extern char *freebsd_get_ifs_buf(int *);
extern int freebsd_ifs_init(int (*cb)(const char *, int));
-extern void freebsd_netgraph_fini(void);
-extern int freebsd_netgraph_init(void);
#endif /* _SND_FREEBSD_H */
==== //depot/projects/soc2009/anchie_send/send_0.2/sendd/proto.c#13 (text+ko) ====
@@ -383,10 +383,12 @@
DBG(&dbg, "%s pkt (%d bytes)", drop ? "dropping" : "delivering",
pi->b->len);
-#if 0
+
+#ifdef SND_OS_freebsd
+ snd_deliver_pkt(pi->os_pkt, pi->b, drop, 1);
+#else
os_specific_deliver_pkt(pi->os_pkt, pi->b, drop, 1);
#endif
- snd_deliver_pkt(pi->os_pkt, pi->b, drop, 1);
free(pi);
}
@@ -431,10 +433,11 @@
snd_put_cga_params(pi->params);
if (sig) free(sig);
pi->b->data = pi->start;
-#if 0
+#ifdef SND_OS_freebsd
+ snd_deliver_pkt(pi->os_pkt, pi->b, drop, 1);
+#else
os_specific_deliver_pkt(pi->os_pkt, pi->b, drop, 1);
#endif
- snd_deliver_pkt(pi->os_pkt, pi->b, drop, 1);
free(pi);
}
@@ -576,7 +579,7 @@
pi->cga = &pi->iph->ip6_src;
break;
case ND_ROUTER_ADVERT:
-#if 0
+#ifndef SND_OS_freebsd
if (!IN6_IS_ADDR_LINKLOCAL(&pi->iph->ip6_src)) {
DBG(&dbg_snd, "RA src addr is not link local");
return (0);
@@ -659,18 +662,18 @@
DBG(&dbg, "%s pkt (%d bytes)", drop ? "dropping" : "delivering",
pi->b->len);
-#if 0
+
+#ifdef SND_OS_freebsd
+ snd_deliver_pkt(pi->os_pkt, pi->b, drop, 1);
+#else
os_specific_deliver_pkt(pi->os_pkt, pi->b, drop, 1);
#endif
- snd_deliver_pkt(pi->os_pkt, pi->b, drop, 1);
+
free(pi);
}
void
snd_recv_pkt(struct sbuff *b, int ifidx, int in, void *pkt)
-#if 0
-snd_recv_pkt(struct sbuff *b, int ifidx, int in)
-#endif
{
int tlen, drop = 0;
int changed = 0;
@@ -686,7 +689,7 @@
DBG(&dbg_snd, "pi->ifinfo->ifidx = %d", ifidx);
-#if 0
+#ifndef SND_OS_freebsd
if (!in)
if (sbuff_pull(b, sizeof (struct ether_header)) == NULL) {
DBG(&dbg_snd, "invalid pkt (not enough for ether header");
@@ -694,7 +697,6 @@
}
}
#endif
-
start = sbuff_data(b);
DBG(&dbg, "%s", in ? "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<" :
@@ -717,7 +719,6 @@
DBG(&dbg_snd, "pkt too small (ip6 hdr)");
goto drop;
}
-
pi->icmp = sbuff_data(b);
if (b->len < sizeof (*(pi->icmp))) {
DBG(&dbg_snd, "pkt too small (icmp6 hdr)");
@@ -753,7 +754,6 @@
drop = 0;
goto done;
}
-
if (snd_parse_opts(&pi->ndopts, sbuff_data(b), b->len) < 0) {
goto drop;
}
@@ -793,12 +793,11 @@
drop = 1;
done:
b->data = start;
- /*
- * ToDo: The packet is here sent through netgraph. Will be sent back
- * to kernel through the input hook.
- */
- /* os_specific_deliver_pkt(pkt, b, drop, changed); */
+#ifdef SND_OS_freebsd
snd_deliver_pkt(pkt, b, drop, changed);
+#else
+ os_specific_deliver_pkt(pkt, b, drop, changed);
+#endif
}
int
@@ -814,8 +813,6 @@
return (-1);
}
#endif
- applog(LOG_ERR, "snd_proto_init");
-
if (snd_proto_nonce_init() < 0 ||
snd_proto_timestamp_init() < 0) {
return (-1);
==== //depot/projects/soc2009/anchie_send/send_0.2/sendd/sendd.c#12 (text+ko) ====
@@ -78,7 +78,11 @@
}
static int
+#ifdef SND_OS_freebsd
do_select(int icmps, int snds, int ctlfd)
+#else
+do_select(int icmps, int ctlfd)
+#endif
{
fd_set fds[1];
int maxfd = -1;
@@ -87,16 +91,19 @@
if (cfd != -1) maxfd = cfd;
maxfd = sendd_max(icmps, maxfd);
maxfd = sendd_max(ctlfd, maxfd);
+#ifdef SND_OS_freebsd
maxfd = sendd_max(snds, maxfd);
-
+#endif
for (;;) {
FD_ZERO(fds);
if (cfd != -1) FD_SET(cfd, fds);
FD_SET(icmps, fds);
FD_SET(ctlfd, fds);
- /* Routing socket instead of using netgraph for ND/SeND */
- /* os_specific_add_fds(fds, &maxfd); */
+#ifdef SND_OS_freebsd
snd_add_fds(fds, &maxfd, snds);
+#else
+ os_specific_add_fds(fds, &maxfd);
+#endif
DBG(&snd_dbg, "after snd_add_fds");
tv = get_next_wait(tvb);
@@ -124,10 +131,11 @@
if (FD_ISSET(ctlfd, fds)) {
snd_ctl_read(ctlfd);
}
-#if 0
+#ifdef SND_OS_freebsd
+ snd_dispatch_fds(fds);
+#else
os_specific_dispatch_fds(fds);
#endif
- snd_dispatch_fds(fds);
snd_replace_non_cga_linklocals();
}
}
@@ -162,7 +170,7 @@
{
const char **lm = applog_get_methods();
- fprintf(stderr, "---> Usage: %s [-fV] [-c <conf>] [-i <iface>] "
+ fprintf(stderr, "Usage: %s [-fV] [-c <conf>] [-i <iface>] "
"[-l <log method>]\n", this);
fprintf(stderr, " log methods: ");
for (; *lm; lm++) {
@@ -174,11 +182,15 @@
int
main(int argc, char **argv)
{
- int r, c, icmps, snds, ctlfd, do_daemon = 1;
+ int r, c, icmps, ctlfd, do_daemon = 1;
+#ifdef SND_OS_freebsd
+ int snds;
+#endif
char *cfile = SNDD_CONF_FILE;
+#ifdef SND_OS_freebsd
icmps = snds = (int *) malloc(sizeof(int));
-
+#endif
#ifdef DEBUG
if (applog_open(L_STDERR, SENDD_NAME) < 0) {
exit(1);
@@ -250,9 +262,13 @@
snd_ssl_init() < 0 ||
snd_cga_init() < 0 ||
snd_params_init() < 0 ||
+#ifdef SND_OS_freebsd
snd_net_init(&icmps, &snds) < 0 ||
icmps < 0 ||
snds < 0 ||
+#else
+ (icmps = snd_net_init()) < 0 ||
+#endif
snd_init_cert() < 0 ||
snd_pkixip_config() < 0 ||
snd_proto_init() < 0 ||
@@ -280,8 +296,11 @@
cfd = 0;
}
#endif
-
+#ifdef SND_OS_freebsd
r = do_select(icmps, snds, ctlfd);
+#else
+ r = do_select(icmps, ctlfd);
+#endif
snd_cleanup();
exit(r);
==== //depot/projects/soc2009/anchie_send/send_0.2/sendd/sendd_local.h#5 (text+ko) ====
@@ -130,7 +130,11 @@
/* net.c */
extern void snd_icmp_sock_read(void);
+#ifdef SND_OS_freebsd
extern int snd_net_init(int *, int *);
+#else
+extern int snd_net_init(void);
+#endif
extern struct sbuff *snd_get_buf(void);
extern void snd_put_buf(struct sbuff *);
extern int snd_send_icmp(struct sbuff *, struct sockaddr_in6 *, int);
More information about the p4-projects
mailing list