Date: Sat, 27 Mar 2010 04:40:19 GMT From: Ana Kukec <anchie@FreeBSD.org> To: Perforce Change Reviews <perforce@FreeBSD.org> Subject: PERFORCE change 176159 for review Message-ID: <201003270440.o2R4eJNC056061@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://p4web.freebsd.org/chv.cgi?CH=176159 Change 176159 by anchie@anchie_malimis on 2010/03/27 04:40:16 SEND now uses native SEND socket to send packets from Neighbor Discovery (ND) kernel stack to userland SEND application, and back from userland to the ND kernel stack. There are few lines of code missing to send the outgoing packet with the if_output() function to the wire. Affected files ... .. //depot/projects/soc2009/anchie_send/send_0.2/sendd/net.c#27 edit .. //depot/projects/soc2009/anchie_send/send_0.2/sendd/proto.c#12 edit .. //depot/projects/soc2009/anchie_send/src/sys/kern/uipc_socket.c#6 edit .. //depot/projects/soc2009/anchie_send/src/sys/netinet/in.h#5 edit .. //depot/projects/soc2009/anchie_send/src/sys/netinet/ip_var.h#7 edit .. //depot/projects/soc2009/anchie_send/src/sys/netinet/raw_ip.c#6 edit .. //depot/projects/soc2009/anchie_send/src/sys/netinet6/icmp6.c#32 edit .. //depot/projects/soc2009/anchie_send/src/sys/netinet6/send.c#34 edit .. //depot/projects/soc2009/anchie_send/src/sys/netinet6/send.h#18 edit Differences ... ==== //depot/projects/soc2009/anchie_send/send_0.2/sendd/net.c#27 (text+ko) ==== @@ -86,6 +86,7 @@ u_char rtm_type; int rtm_seq; int in; + int ifidx; }; void snd_sock_read(struct snd_ifinfo *p); @@ -143,21 +144,23 @@ { struct snd_packet_info *pi; struct rt_msghdr *rtm; + struct snd_hdr *snd_hdr; if (drop) { snd_put_buf(b); return; } + 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); -#if 0 - b->data -= sizeof (struct if_announcemsghdr); - b->len += sizeof (struct if_announcemsghdr); -#endif + //b->data -= sizeof (struct if_announcemsghdr); + //b->len += sizeof (struct if_announcemsghdr); DBG(&dbg_snd, "%d bytes on %s", b->len, pi->ifinfo->name); @@ -181,7 +184,21 @@ snd_put_buf(b); return; } +#endif + + b->data -= SEND_HDR_LEN; + b->len += SEND_HDR_LEN; + snd_hdr = sbuff_data(b); + snd_hdr->direction = pi->in; + snd_hdr->ifidx = pi->ifinfo->ifidx; + if (send(sndsock, b->data, b->len, 0) < 0) { + DBG(&dbg_snd, "Failed to send SEND message back to kernel."); + perror("Failed"); + snd_put_buf(b); + return; + } + snd_put_buf(b); return; @@ -255,6 +272,8 @@ 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; @@ -277,6 +296,26 @@ b->len = n; + snd_hdr = sbuff_pull(b, SEND_HDR_LEN); + direction = snd_hdr->direction; + switch(direction) { + case SND_IN: + applog(LOG_ERR, "Direction: SND_IN"); + pi->ifinfo = p; + pi->in = 1; + snd_recv_pkt(b, p->ifidx, SND_IN, pi); + break; + case SND_OUT: + applog(LOG_ERR, "Direction: SND_OUT"); + pi->ifinfo = p; + pi->in = 0; + snd_recv_pkt(b, p->ifidx, SND_OUT, pi); + break; + default: + 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__); @@ -324,6 +363,7 @@ applog(LOG_ERR, "%s: Unsupported routing message type.", __FUNCTION__); goto done; } +#endif done: /* ToDo: Free memory! */ @@ -403,13 +443,22 @@ return (-1); } #endif +#define IPPROTO_SEND 259 + if ((*sndsocket = socket(PF_INET, SOCK_RAW, IPPROTO_SEND)) < 0) { + applog(LOG_ERR, "%s: socket: %s", __FUNCTION__, + strerror(errno)); + return(-1); + } else { + applog(LOG_ERR, "%s: SEND socket created.", __FUNCTION__); + } + 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)); @@ -417,6 +466,7 @@ } else { applog(LOG_ERR, "%s: routing socket created.", __FUNCTION__); } +#endif icmp6sock = *icmp6socket; sndsock = *sndsocket; ==== //depot/projects/soc2009/anchie_send/send_0.2/sendd/proto.c#12 (text+ko) ==== @@ -684,6 +684,8 @@ return; } + DBG(&dbg_snd, "pi->ifinfo->ifidx = %d", ifidx); + #if 0 if (!in) if (sbuff_pull(b, sizeof (struct ether_header)) == NULL) { ==== //depot/projects/soc2009/anchie_send/src/sys/kern/uipc_socket.c#6 (text+ko) ==== @@ -1186,12 +1186,15 @@ goto release; } } else if (addr == NULL) { + /* XXX-AK: */ + if (so->so_proto->pr_protocol != 259) { SOCKBUF_UNLOCK(&so->so_snd); if (so->so_proto->pr_flags & PR_CONNREQUIRED) error = ENOTCONN; else error = EDESTADDRREQ; goto release; + } } } space = sbspace(&so->so_snd); ==== //depot/projects/soc2009/anchie_send/src/sys/netinet/in.h#5 (text+ko) ==== ==== //depot/projects/soc2009/anchie_send/src/sys/netinet/ip_var.h#7 (text+ko) ==== ==== //depot/projects/soc2009/anchie_send/src/sys/netinet/raw_ip.c#6 (text+ko) ==== ==== //depot/projects/soc2009/anchie_send/src/sys/netinet6/icmp6.c#32 (text+ko) ==== @@ -94,6 +94,7 @@ #include <netinet/in.h> #include <netinet/in_pcb.h> #include <netinet/in_var.h> +#include <netinet/ip_var.h> #include <netinet/ip6.h> #include <netinet/icmp6.h> #include <netinet/tcp_var.h> @@ -780,7 +781,8 @@ /* Send incoming SeND-protected/ND packet to user space. */ if (send_input_hook != NULL) { IP6_EXTHDR_CHECK(m, off, icmp6len, IPPROTO_DONE); - send_input_hook(m, ifp, SND_IN, ip6len); + printf("send_sendso_input_hook\n"); + send_sendso_input_hook(V_send_so, m, SND_IN, ip6len); } else { /* give up local */ nd6_rs_input(m, off, icmp6len); @@ -790,7 +792,8 @@ } if (send_input_hook != NULL) { IP6_EXTHDR_CHECK(m, off, icmp6len, IPPROTO_DONE); - send_input_hook(n, ifp, SND_IN, ip6len); + printf("send_sendso_input_hook\n"); + send_sendso_input_hook(V_send_so, m, SND_IN, ip6len); return (IPPROTO_DONE); } else nd6_rs_input(n, off, icmp6len); @@ -807,7 +810,8 @@ /* Send incoming SeND-protected/ND packet to user space. */ if (send_input_hook != NULL) { - send_input_hook(m, ifp, SND_IN, ip6len); + + send_sendso_input_hook(V_send_so, m, SND_IN, ip6len); return (IPPROTO_DONE); } else nd6_ra_input(m, off, icmp6len); @@ -815,7 +819,7 @@ goto freeit; } if (send_input_hook != NULL) { - send_input_hook(n, ifp, SND_IN, ip6len); + send_sendso_input_hook(V_send_so, m, SND_IN, ip6len); return (IPPROTO_DONE); } else nd6_ra_input(n, off, icmp6len); @@ -832,7 +836,7 @@ if (send_input_hook != NULL) { /* Send incoming SeND/ND packet to user space. */ printf("%s: send_input_hook m=%p\n", __func__, m); - send_input_hook(m, ifp, SND_IN, ip6len); + send_sendso_input_hook(V_send_so, m, SND_IN, ip6len); } else { /* give up local */ nd6_ns_input(m, off, icmp6len); @@ -843,7 +847,7 @@ if (send_input_hook != NULL) { /* Send incoming SeND/ND packet to user space. */ printf("%s: send_input_hook n=%p\n", __func__, n); - send_input_hook(n, ifp, SND_IN, ip6len); + send_sendso_input_hook(V_send_so, m, SND_IN, ip6len); } else nd6_ns_input(n, off, icmp6len); /* m stays. */ @@ -859,7 +863,7 @@ /* Send incoming SeND-protected/ND packet to user space. */ if (send_input_hook != NULL) { - send_input_hook(m, ifp, SND_IN, ip6len); + send_sendso_input_hook(V_send_so, m, SND_IN, ip6len); return (IPPROTO_DONE); } else { /* give up local */ @@ -869,7 +873,7 @@ goto freeit; } if (send_input_hook != NULL) - send_input_hook(n, ifp, SND_IN, ip6len); + send_sendso_input_hook(V_send_so, m, SND_IN, ip6len); else nd6_na_input(n, off, icmp6len); /* m stays. */ @@ -885,7 +889,7 @@ /* Send incoming SeND-protected/ND packet to user space. */ if (send_input_hook != NULL) { - send_input_hook(m, ifp, SND_IN, ip6len); + send_sendso_input_hook(V_send_so, m, SND_IN, ip6len); return (IPPROTO_DONE); } else { /* give up local */ @@ -895,7 +899,7 @@ goto freeit; } if (send_input_hook != NULL) { - send_input_hook(n, ifp, SND_IN, ip6len); + send_sendso_input_hook(V_send_so, m, SND_IN, ip6len); return (IPPROTO_DONE); } else icmp6_redirect_input(n, off); ==== //depot/projects/soc2009/anchie_send/src/sys/netinet6/send.c#34 (text+ko) ==== @@ -45,12 +45,14 @@ #include <net/route.h> #include <net/if.h> +#include <net/if_var.h> #include <netinet6/in6_var.h> #include <netinet6/nd6.h> #include <netinet6/scope6_var.h> #include <netinet6/send.h> + MALLOC_DEFINE(M_SEND, "send", "Secure Neighbour Discovery"); static int @@ -200,11 +202,32 @@ printf("send_uattach: proto = %d\n", proto); V_send_so = so; - /* V_send_so se ko arguement predaje send_sendso_output() funkciji */ return error; } +static int +sosend_rcv(struct socket *so, int flags, struct mbuf *m, struct sockaddr *nam, + struct mbuf *control, struct thread *td) +{ + struct ifnet *ifp; + struct snd_hdr *snd_hdr; + int if_index; + + printf("sosend_rcv \n"); + + snd_hdr = mtod(m, struct snd_hdr *); + if_index = snd_hdr->ifidx; + printf("direction: %d, ifidx: %d \n", snd_hdr->direction, snd_hdr->ifidx); +#if 0 + ifnet_setbyindex(snd_hdr->ifidx, ifp); + m_adj(n, sizeof(struct snd_hdr)); + send_output_hook(m, ifp, snd_hdr->direction); +#endif + + return 0; +} + /* * Send a message to the SEND daemon on the SEND socket. */ @@ -214,6 +237,7 @@ u_int len; void *data; struct ip6_hdr *ip6; + struct snd_hdr *snd_hdr; /* * Make sure to clear any possible internally embedded scope before @@ -240,35 +264,26 @@ m_copydata(m, 0, msglen, data); + M_PREPEND(m, SEND_HDR_LEN, M_DONTWAIT); + if ((m == NULL && (m = m_pullup(m, len + SEND_HDR_LEN)) == NULL)) { + m_freem(m); + 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. */ - if (s) { -#if 0 - SOCKBUF_LOCK(&s->so_rcv); - sbappendrecord_locked(&s->so_rcv, m); - sorwakeup_locked(s); - //SOCKBUF_UNLOCK(&s->so_rcv); -#endif - - struct sockaddr_in6 fromsa; - - bzero(&fromsa, sizeof(fromsa)); - fromsa.sin6_family = AF_INET6; - fromsa.sin6_len = sizeof(fromsa); - fromsa.sin6_addr = ip6->ip6_src; - SOCKBUF_LOCK(&s->so_rcv); - if (sbappendaddr_locked(&s->so_rcv, (struct sockaddr *)&fromsa, - m, (struct mbuf *)0) == 0) { - SOCKBUF_UNLOCK(&s->so_rcv); - } else { + if (s) { + SOCKBUF_LOCK(&s->so_rcv); + sbappendrecord_locked(&s->so_rcv, m); sorwakeup_locked(s); - } + return 0; + } - return 0; - } - m_freem(m); free(data, M_SEND); @@ -278,8 +293,9 @@ static void send_close(struct socket *so) { - - V_send_so = NULL; + /* XXX-AK: Memory leakage! */ + if (V_send_so) + V_send_so = NULL; printf("pru_detach: send_close\n"); //soisdisconnected(so); } @@ -287,7 +303,7 @@ struct pr_usrreqs send_usrreqs = { // Read sys/kern/uipc_socket.c .pru_attach = send_uattach, - //.pru_sosend = sosend_sndpacket, + .pru_send = sosend_rcv, .pru_detach = send_close }; ==== //depot/projects/soc2009/anchie_send/src/sys/netinet6/send.h#18 (text+ko) ==== @@ -30,6 +30,13 @@ #define RTM_SND_OUT 0 /* Outgoing RTM SeND packet sent to user space */ #define RTM_SND_IN 1 /* Incoming RTM SeND packet sent to user space */ +#define SEND_HDR_LEN sizeof(struct snd_hdr) + +struct snd_hdr { + int direction; + int ifidx; +}; + extern int (*send_input_hook)(struct mbuf *, struct ifnet *, int, int); extern int (*send_output_hook)(struct mbuf *, struct ifnet *, int);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201003270440.o2R4eJNC056061>