From owner-freebsd-net@FreeBSD.ORG Fri Dec 12 13:46:32 2008 Return-Path: Delivered-To: freebsd-net@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 85643106564A; Fri, 12 Dec 2008 13:46:32 +0000 (UTC) (envelope-from rrs@lakerest.net) Received: from lakerest.net (unknown [IPv6:2001:240:585:2:203:6dff:fe1a:4ddc]) by mx1.freebsd.org (Postfix) with ESMTP id 00CE18FC18; Fri, 12 Dec 2008 13:46:31 +0000 (UTC) (envelope-from rrs@lakerest.net) Received: from [10.1.1.54] ([10.1.1.54]) (authenticated bits=0) by lakerest.net (8.14.1/8.14.1) with ESMTP id mBCDkUZH017234 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NOT); Fri, 12 Dec 2008 08:46:31 -0500 (EST) (envelope-from rrs@lakerest.net) DKIM-Signature: a=rsa-sha1; c=simple/simple; d=lakerest.net; s=mail; t=1229089591; h=Cc:Message-Id:From:To:In-Reply-To:Content-Type: Mime-Version:Subject:Date:References:X-Mailer; b=PplwOYWEyNxbU8M7o8 2P9dylvTnuF/vokAoR7zUifbqGPUoSodXj5zqhSGBAODAVo+2hgvv1/z8DI6g+ea912 Q== Message-Id: <13C9478E-CBF6-4EDA-8E78-AD76549EB844@lakerest.net> From: Randall Stewart To: "Bruce M. Simpson" In-Reply-To: <494157DF.6030802@FreeBSD.org> Content-Type: multipart/mixed; boundary=Apple-Mail-78--473196051 Mime-Version: 1.0 (Apple Message framework v929.2) Date: Fri, 12 Dec 2008 08:46:30 -0500 References: <49249443.8050707@elischer.org> <76CF7D15-251F-4E43-86BE-AD96F48AF123@lakerest.net> <200811201450.30016.max@love2party.net> <24BD4A21-E10D-4E09-8C33-3FCF930A0495@lakerest.net> <494157DF.6030802@FreeBSD.org> X-Mailer: Apple Mail (2.929.2) Cc: freebsd-net Subject: Re: Heads up --- Thinking about UDP and tunneling X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 12 Dec 2008 13:46:32 -0000 --Apple-Mail-78--473196051 Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit Ok: Here is an updated patch it: 1) Fixes style9 issues (I hope.. I went back to vi and tried tabs :-0.. sigh one of these doys I will figure out why my .emacs settings just never cut it :-() 2) move to _t typedef 3) Allow multicast/broadcast to also be tunneled. 4) Binding is now no longer a requirement to set tunneling mode, in fact most protocols had better NOT have bound.. first set options, then bind :-) There was one thing I was a bit leary of for <3>. In the loop for going through all the inp's of UDP that are listening to a m-cast/b-cast I could not release the INP_INFO_LOCK() in other cases I make sure all locks are released when we call into the tunneling protocol. I think this will be ok as long as the tunnelee does not try to use the INP_INFO_LOCK of the UDP world... I know for SCTP this is a non-issue.. but it may be something we want to think about... not sure. If there are no serious objections I will submit this into head.. and followed behind it I will send in the changes so SCTP can be tunneled over this new mechanism :-) R --Apple-Mail-78--473196051 Content-Disposition: attachment; filename=new_udp_diff.txt Content-Type: text/plain; x-unix-mode=0644; name="new_udp_diff.txt" Content-Transfer-Encoding: 7bit Index: netinet/udp_usrreq.c =================================================================== --- netinet/udp_usrreq.c (revision 185928) +++ netinet/udp_usrreq.c (working copy) @@ -488,10 +488,25 @@ struct mbuf *n; n = m_copy(m, 0, M_COPYALL); - if (n != NULL) - udp_append(last, ip, n, iphlen + - sizeof(struct udphdr), &udp_in); - INP_RUNLOCK(last); + + if (last->inp_ppcb == NULL) { + if (n != NULL) + udp_append(last, ip, n, iphlen + + sizeof(struct udphdr), &udp_in); + INP_RUNLOCK(last); + } else { + /* Engage the tunneling protocol + * we will have to leave the info_lock + * up, since we are hunting through + * multiple UDP inp's hope we don't break :-( + */ + udp_tunnel_function_t tunnel_func; + + INP_RUNLOCK(last); + tunnel_func = (udp_tunnel_function_t)last->inp_ppcb; + INP_RUNLOCK(last); + tunnel_func(m, iphlen); + } } last = inp; /* @@ -516,10 +531,25 @@ V_udpstat.udps_noportbcast++; goto badheadlocked; } - udp_append(last, ip, m, iphlen + sizeof(struct udphdr), - &udp_in); - INP_RUNLOCK(last); - INP_INFO_RUNLOCK(&V_udbinfo); + if (last->inp_ppcb == NULL) { + udp_append(last, ip, m, iphlen + sizeof(struct udphdr), + &udp_in); + INP_RUNLOCK(last); + INP_INFO_RUNLOCK(&V_udbinfo); + } else { + /* Engage the tunneling protocol + * we must make sure all locks + * are released when we call the + * tunneling protocol. + */ + udp_tunnel_function_t tunnel_func; + + INP_RUNLOCK(last); + INP_INFO_RUNLOCK(&V_udbinfo); + tunnel_func = (udp_tunnel_function_t)last->inp_ppcb; + INP_RUNLOCK(last); + tunnel_func(m, iphlen); + } return; } @@ -563,6 +593,18 @@ INP_RUNLOCK(inp); goto badunlocked; } + if (inp->inp_ppcb) { + /* Engage the tunneling protocol + * we must make sure all locks + * are released when we call the + * tunneling protocol. + */ + udp_tunnel_function_t tunnel_func; + tunnel_func = (udp_tunnel_function_t)inp->inp_ppcb; + INP_RUNLOCK(inp); + tunnel_func(m, iphlen); + return; + } udp_append(inp, ip, m, iphlen + sizeof(struct udphdr), &udp_in); INP_RUNLOCK(inp); return; @@ -1138,10 +1180,41 @@ INP_INFO_WUNLOCK(&V_udbinfo); inp->inp_vflag |= INP_IPV4; inp->inp_ip_ttl = V_ip_defttl; + /* + * UDP does not have a per-protocol + * pcb (inp->inp_ppcb). We use this + * pointer for kernel tunneling pointer. + * If we ever need to have a protocol + * block we will need to move this + * function pointer there. Null + * in this pointer means "do the normal + * thing". + */ + inp->inp_ppcb = NULL; INP_WUNLOCK(inp); return (0); } +int +udp_set_kernel_tunneling(struct socket *so, udp_tunnel_function_t f) +{ + struct inpcb *inp; + inp = (struct inpcb *)so->so_pcb; + + if (so->so_type != SOCK_DGRAM) { + /* Not UDP socket... sorry */ + return (ENOTSUP); + } + if (inp == NULL) { + /* NULL INP? */ + return (EINVAL); + } + INP_WLOCK(inp); + inp->inp_ppcb = f; + INP_WUNLOCK(inp); + return (0); +} + static int udp_bind(struct socket *so, struct sockaddr *nam, struct thread *td) { Index: netinet/udp_var.h =================================================================== --- netinet/udp_var.h (revision 185928) +++ netinet/udp_var.h (working copy) @@ -107,6 +107,10 @@ void udp_input(struct mbuf *, int); struct inpcb *udp_notify(struct inpcb *inp, int errno); int udp_shutdown(struct socket *so); + + +typedef void(*udp_tunnel_function_t)(struct mbuf *, int off); +int udp_set_kernel_tunneling(struct socket *so, udp_tunnel_function_t f); #endif #endif Index: netinet6/udp6_usrreq.c =================================================================== --- netinet6/udp6_usrreq.c (revision 185928) +++ netinet6/udp6_usrreq.c (working copy) @@ -286,9 +286,21 @@ struct mbuf *n; if ((n = m_copy(m, 0, M_COPYALL)) != NULL) { - INP_RLOCK(last); - udp6_append(last, n, off, &fromsa); - INP_RUNLOCK(last); + if (last->inp_ppcb) { + /* Engage the tunneling protocol + * we will have to leave the info_lock + * up, since we are hunting through + * multiple UDP inp's hope we don't break :-( + */ + udp_tunnel_function_t tunnel_func; + tunnel_func = (udp_tunnel_function_t)last->inp_ppcb; + INP_RUNLOCK(last); + tunnel_func(m, off); + } else { + INP_RLOCK(last); + udp6_append(last, n, off, &fromsa); + INP_RUNLOCK(last); + } } } last = inp; @@ -317,6 +329,19 @@ } INP_RLOCK(last); INP_INFO_RUNLOCK(&V_udbinfo); + if (last->inp_ppcb) { + /* Engage the tunneling protocol + * we must make sure all locks + * are released when we call the + * tunneling protocol. + */ + udp_tunnel_function_t tunnel_func; + + tunnel_func = (udp_tunnel_function_t)inp->inp_ppcb; + INP_RUNLOCK(last); + tunnel_func(m, off); + return (IPPROTO_DONE); + } udp6_append(last, m, off, &fromsa); INP_RUNLOCK(last); return (IPPROTO_DONE); @@ -354,6 +379,18 @@ } INP_RLOCK(inp); INP_INFO_RUNLOCK(&V_udbinfo); + if (inp->inp_ppcb) { + /* Engage the tunneling protocol + * we must make sure all locks + * are released when we call the + * tunneling protocol. + */ + udp_tunnel_function_t tunnel_func; + tunnel_func = (udp_tunnel_function_t)inp->inp_ppcb; + INP_RUNLOCK(inp); + tunnel_func(m, off); + return (IPPROTO_DONE); + } udp6_append(inp, m, off, &fromsa); INP_RUNLOCK(inp); return (IPPROTO_DONE); --Apple-Mail-78--473196051 Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit On Dec 11, 2008, at 1:11 PM, Bruce M. Simpson wrote: > Hi, > > I am missing context of what Max's suggestion was, do you have a > reference to an old email thread? > > Style bugs: > * needs style(9) and whitespace cleanup. > * C typedefs should be suffixed with _t for consistency with other > kernel typedefs. > * Function typedefs usually named like foo_func_t (see other > subsystems) > > Have you looked at m_apply() ? It already exists for stuff like this > i.e. functions which act on an mbuf chain, although it doesn't > necessarily expect chain heads. > > cheers > BMS > ------------------------------ Randall Stewart 803-317-4952 (cell) 803-345-0391(direct) --Apple-Mail-78--473196051--