summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrwatson <rwatson@FreeBSD.org>2008-07-05 18:03:39 +0000
committerrwatson <rwatson@FreeBSD.org>2008-07-05 18:03:39 +0000
commit6ee57a292b96843561f46cb712ea717ccd9c8053 (patch)
tree02fc9a3bea600d17e11dd2ae1bfb307303f8a3ce
parenteb53283166f3d5ee362e92e9377cf2b75bc7c22c (diff)
downloadFreeBSD-src-6ee57a292b96843561f46cb712ea717ccd9c8053.zip
FreeBSD-src-6ee57a292b96843561f46cb712ea717ccd9c8053.tar.gz
Improve approximation of style(9) in raw socket code.
-rw-r--r--sys/net/raw_cb.c28
-rw-r--r--sys/net/raw_cb.h7
-rw-r--r--sys/net/raw_usrreq.c73
-rw-r--r--sys/netinet/raw_ip.c137
-rw-r--r--sys/netinet6/raw_ip6.c132
5 files changed, 197 insertions, 180 deletions
diff --git a/sys/net/raw_cb.c b/sys/net/raw_cb.c
index dd41180..3bbf3d2 100644
--- a/sys/net/raw_cb.c
+++ b/sys/net/raw_cb.c
@@ -1,6 +1,7 @@
/*-
* Copyright (c) 1980, 1986, 1993
- * The Regents of the University of California. All rights reserved.
+ * The Regents of the University of California.
+ * All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -58,15 +59,13 @@ const static u_long raw_sendspace = RAWSNDQ;
const static u_long raw_recvspace = RAWRCVQ;
/*
- * Allocate a control block and a nominal amount
- * of buffer space for the socket.
+ * Allocate a control block and a nominal amount of buffer space for the
+ * socket.
*/
int
-raw_attach(so, proto)
- register struct socket *so;
- int proto;
+raw_attach(struct socket *so, int proto)
{
- register struct rawcb *rp = sotorawcb(so);
+ struct rawcb *rp = sotorawcb(so);
int error;
/*
@@ -89,12 +88,10 @@ raw_attach(so, proto)
}
/*
- * Detach the raw connection block and discard
- * socket resources.
+ * Detach the raw connection block and discard socket resources.
*/
void
-raw_detach(rp)
- register struct rawcb *rp;
+raw_detach(struct rawcb *rp)
{
struct socket *so = rp->rcb_socket;
@@ -116,8 +113,7 @@ raw_detach(rp)
* Disconnect raw socket.
*/
void
-raw_disconnect(rp)
- struct rawcb *rp;
+raw_disconnect(struct rawcb *rp)
{
#ifdef notdef
@@ -131,12 +127,10 @@ raw_disconnect(rp)
#include <sys/mbuf.h>
int
-raw_bind(so, nam)
- register struct socket *so;
- struct mbuf *nam;
+raw_bind(struct socket *so, struct mbuf *nam)
{
struct sockaddr *addr = mtod(nam, struct sockaddr *);
- register struct rawcb *rp;
+ struct rawcb *rp;
if (ifnet == 0)
return (EADDRNOTAVAIL);
diff --git a/sys/net/raw_cb.h b/sys/net/raw_cb.h
index 4e6b77a..32f35ed 100644
--- a/sys/net/raw_cb.h
+++ b/sys/net/raw_cb.h
@@ -1,6 +1,7 @@
/*-
* Copyright (c) 1980, 1986, 1993
- * The Regents of the University of California. All rights reserved.
+ * The Regents of the University of California.
+ * All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -36,8 +37,8 @@
#include <sys/queue.h>
/*
- * Raw protocol interface control block. Used
- * to tie a socket to the generic raw interface.
+ * Raw protocol interface control block. Used to tie a socket to the generic
+ * raw interface.
*/
struct rawcb {
LIST_ENTRY(rawcb) list;
diff --git a/sys/net/raw_usrreq.c b/sys/net/raw_usrreq.c
index 22f3e7b..fb5f429 100644
--- a/sys/net/raw_usrreq.c
+++ b/sys/net/raw_usrreq.c
@@ -1,6 +1,7 @@
/*-
* Copyright (c) 1980, 1986, 1993
- * The Regents of the University of California. All rights reserved.
+ * The Regents of the University of California.
+ * All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -52,29 +53,25 @@ MTX_SYSINIT(rawcb_mtx, &rawcb_mtx, "rawcb", MTX_DEF);
* Initialize raw connection block q.
*/
void
-raw_init()
+raw_init(void)
{
LIST_INIT(&rawcb_list);
}
-
/*
- * Raw protocol input routine. Find the socket
- * associated with the packet(s) and move them over. If
- * nothing exists for this packet, drop it.
+ * Raw protocol input routine. Find the socket associated with the packet(s)
+ * and move them over. If nothing exists for this packet, drop it.
*/
/*
* Raw protocol interface.
*/
void
-raw_input(m0, proto, src, dst)
- struct mbuf *m0;
- register struct sockproto *proto;
- struct sockaddr *src, *dst;
+raw_input(struct mbuf *m0, struct sockproto *proto, struct sockaddr *src,
+ struct sockaddr *dst)
{
- register struct rawcb *rp;
- register struct mbuf *m = m0;
+ struct rawcb *rp;
+ struct mbuf *m = m0;
struct socket *last;
last = 0;
@@ -86,12 +83,11 @@ raw_input(m0, proto, src, dst)
rp->rcb_proto.sp_protocol != proto->sp_protocol)
continue;
/*
- * We assume the lower level routines have
- * placed the address in a canonical format
- * suitable for a structure comparison.
+ * We assume the lower level routines have placed the address
+ * in a canonical format suitable for a structure comparison.
*
- * Note that if the lengths are not the same
- * the comparison will fail at the first byte.
+ * Note that if the lengths are not the same the comparison
+ * will fail at the first byte.
*/
#define equal(a1, a2) \
(bcmp((caddr_t)(a1), (caddr_t)(a2), a1->sa_len) == 0)
@@ -107,9 +103,8 @@ raw_input(m0, proto, src, dst)
n, (struct mbuf *)0) == 0)
/* should notify about lost packet */
m_freem(n);
- else {
+ else
sorwakeup(last);
- }
}
}
last = rp->rcb_socket;
@@ -118,9 +113,8 @@ raw_input(m0, proto, src, dst)
if (sbappendaddr(&last->so_rcv, src,
m, (struct mbuf *)0) == 0)
m_freem(m);
- else {
+ else
sorwakeup(last);
- }
} else
m_freem(m);
mtx_unlock(&rawcb_mtx);
@@ -128,10 +122,7 @@ raw_input(m0, proto, src, dst)
/*ARGSUSED*/
void
-raw_ctlinput(cmd, arg, dummy)
- int cmd;
- struct sockaddr *arg;
- void *dummy;
+raw_ctlinput(int cmd, struct sockaddr *arg, void *dummy)
{
if (cmd < 0 || cmd >= PRC_NCMDS)
@@ -168,7 +159,7 @@ raw_uattach(struct socket *so, int proto, struct thread *td)
/*
* Implementors of raw sockets will already have allocated the PCB,
- * so it must be non-NULL here.
+ * so it must be non-NULL here.
*/
KASSERT(sotorawcb(so) != NULL, ("raw_uattach: so_pcb == NULL"));
@@ -183,13 +174,15 @@ raw_uattach(struct socket *so, int proto, struct thread *td)
static int
raw_ubind(struct socket *so, struct sockaddr *nam, struct thread *td)
{
- return EINVAL;
+
+ return (EINVAL);
}
static int
raw_uconnect(struct socket *so, struct sockaddr *nam, struct thread *td)
{
- return EINVAL;
+
+ return (EINVAL);
}
/* pru_connect2 is EOPNOTSUPP */
@@ -210,12 +203,11 @@ raw_udisconnect(struct socket *so)
struct rawcb *rp = sotorawcb(so);
KASSERT(rp != NULL, ("raw_udisconnect: rp == NULL"));
- if (rp->rcb_faddr == 0) {
- return ENOTCONN;
- }
+ if (rp->rcb_faddr == 0)
+ return (ENOTCONN);
raw_disconnect(rp);
soisdisconnected(so);
- return 0;
+ return (0);
}
/* pru_listen is EOPNOTSUPP */
@@ -226,19 +218,18 @@ raw_upeeraddr(struct socket *so, struct sockaddr **nam)
struct rawcb *rp = sotorawcb(so);
KASSERT(rp != NULL, ("raw_upeeraddr: rp == NULL"));
- if (rp->rcb_faddr == 0) {
- return ENOTCONN;
- }
+ if (rp->rcb_faddr == 0)
+ return (ENOTCONN);
*nam = sodupsockaddr(rp->rcb_faddr, M_WAITOK);
- return 0;
+ return (0);
}
/* pru_rcvd is EOPNOTSUPP */
/* pru_rcvoob is EOPNOTSUPP */
static int
-raw_usend(struct socket *so, int flags, struct mbuf *m,
- struct sockaddr *nam, struct mbuf *control, struct thread *td)
+raw_usend(struct socket *so, int flags, struct mbuf *m, struct sockaddr *nam,
+ struct mbuf *control, struct thread *td)
{
int error;
struct rawcb *rp = sotorawcb(so);
@@ -282,7 +273,7 @@ raw_ushutdown(struct socket *so)
KASSERT(sotorawcb(so) != NULL, ("raw_ushutdown: rp == NULL"));
socantsendmore(so);
- return 0;
+ return (0);
}
static int
@@ -292,9 +283,9 @@ raw_usockaddr(struct socket *so, struct sockaddr **nam)
KASSERT(rp != NULL, ("raw_usockaddr: rp == NULL"));
if (rp->rcb_laddr == 0)
- return EINVAL;
+ return (EINVAL);
*nam = sodupsockaddr(rp->rcb_laddr, M_WAITOK);
- return 0;
+ return (0);
}
struct pr_usrreqs raw_usrreqs = {
diff --git a/sys/netinet/raw_ip.c b/sys/netinet/raw_ip.c
index 32a27d8..d9a43e0 100644
--- a/sys/netinet/raw_ip.c
+++ b/sys/netinet/raw_ip.c
@@ -1,6 +1,7 @@
/*-
* Copyright (c) 1982, 1986, 1988, 1993
- * The Regents of the University of California. All rights reserved.
+ * The Regents of the University of California.
+ * All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -82,14 +83,18 @@ ip_fw_ctl_t *ip_fw_ctl_ptr = NULL;
ip_dn_ctl_t *ip_dn_ctl_ptr = NULL;
/*
- * hooks for multicast routing. They all default to NULL,
- * so leave them not initialized and rely on BSS being set to 0.
+ * Hooks for multicast routing. They all default to NULL, so leave them not
+ * initialized and rely on BSS being set to 0.
*/
-/* The socket used to communicate with the multicast routing daemon. */
+/*
+ * The socket used to communicate with the multicast routing daemon.
+ */
struct socket *ip_mrouter;
-/* The various mrouter and rsvp functions */
+/*
+ * The various mrouter and rsvp functions.
+ */
int (*ip_mrouter_set)(struct socket *, struct sockopt *);
int (*ip_mrouter_get)(struct socket *, struct sockopt *);
int (*ip_mrouter_done)(void);
@@ -134,9 +139,9 @@ rip_init(void)
LIST_INIT(&ripcb);
ripcbinfo.ipi_listhead = &ripcb;
/*
- * XXX We don't use the hash list for raw IP, but it's easier
- * to allocate a one entry hash list than it is to check all
- * over the place for hashbase == NULL.
+ * XXX We don't use the hash list for raw IP, but it's easier to
+ * allocate a one entry hash list than it is to check all over the
+ * place for hashbase == NULL.
*/
ripcbinfo.ipi_hashbase = hashinit(1, M_PCB, &ripcbinfo.ipi_hashmask);
ripcbinfo.ipi_porthashbase = hashinit(1, M_PCB,
@@ -144,8 +149,8 @@ rip_init(void)
ripcbinfo.ipi_zone = uma_zcreate("ripcb", sizeof(struct inpcb),
NULL, NULL, rip_inpcb_init, NULL, UMA_ALIGN_PTR, UMA_ZONE_NOFREE);
uma_zone_set_max(ripcbinfo.ipi_zone, maxsockets);
- EVENTHANDLER_REGISTER(maxsockets_change, rip_zone_change,
- NULL, EVENTHANDLER_PRI_ANY);
+ EVENTHANDLER_REGISTER(maxsockets_change, rip_zone_change, NULL,
+ EVENTHANDLER_PRI_ANY);
}
static struct sockaddr_in ripsrc = { sizeof(ripsrc), AF_INET };
@@ -190,13 +195,12 @@ raw_append(struct inpcb *last, struct ip *ip, struct mbuf *n)
sorwakeup_locked(so);
} else
m_freem(n);
- return policyfail;
+ return (policyfail);
}
/*
- * Setup generic address and protocol structures
- * for raw_input routine, then pass them along with
- * mbuf chain.
+ * Setup generic address and protocol structures for raw_input routine, then
+ * pass them along with mbuf chain.
*/
void
rip_input(struct mbuf *m, int off)
@@ -253,8 +257,8 @@ rip_input(struct mbuf *m, int off)
}
/*
- * Generate IP header and pass packet to ip_output.
- * Tack on options user may have setup with control call.
+ * Generate IP header and pass packet to ip_output. Tack on options user may
+ * have setup with control call.
*/
int
rip_output(struct mbuf *m, struct socket *so, u_long dst)
@@ -266,8 +270,8 @@ rip_output(struct mbuf *m, struct socket *so, u_long dst)
IP_ALLOWBROADCAST;
/*
- * If the user handed us a complete IP packet, use it.
- * Otherwise, allocate an mbuf for a header and fill it in.
+ * If the user handed us a complete IP packet, use it. Otherwise,
+ * allocate an mbuf for a header and fill it in.
*/
if ((inp->inp_flags & INP_HDRINCL) == 0) {
if (m->m_pkthdr.len + sizeof(struct ip) > IP_MAXPACKET) {
@@ -309,19 +313,24 @@ rip_output(struct mbuf *m, struct socket *so, u_long dst)
return (EPERM);
}
}
- /* don't allow both user specified and setsockopt options,
- and don't allow packet length sizes that will crash */
- if (((ip->ip_hl != (sizeof (*ip) >> 2))
- && inp->inp_options)
+
+ /*
+ * Don't allow both user specified and setsockopt options,
+ * and don't allow packet length sizes that will crash.
+ */
+ if (((ip->ip_hl != (sizeof (*ip) >> 2)) && inp->inp_options)
|| (ip->ip_len > m->m_pkthdr.len)
|| (ip->ip_len < (ip->ip_hl << 2))) {
INP_RUNLOCK(inp);
m_freem(m);
- return EINVAL;
+ return (EINVAL);
}
if (ip->ip_id == 0)
ip->ip_id = ip_newid();
- /* XXX prevent ip_output from overwriting header fields */
+
+ /*
+ * XXX prevent ip_output from overwriting header fields.
+ */
flags |= IP_RAWOUTPUT;
ipstat.ips_rawout++;
}
@@ -336,7 +345,7 @@ rip_output(struct mbuf *m, struct socket *so, u_long dst)
error = ip_output(m, inp->inp_options, NULL, flags,
inp->inp_moptions, inp);
INP_RUNLOCK(inp);
- return error;
+ return (error);
}
/*
@@ -510,11 +519,11 @@ rip_ctloutput(struct socket *so, struct sockopt *sopt)
}
/*
- * This function exists solely to receive the PRC_IFDOWN messages which
- * are sent by if_down(). It looks for an ifaddr whose ifa_addr is sa,
- * and calls in_ifadown() to remove all routes corresponding to that address.
- * It also receives the PRC_IFUP messages from if_up() and reinstalls the
- * interface routes.
+ * This function exists solely to receive the PRC_IFDOWN messages which are
+ * sent by if_down(). It looks for an ifaddr whose ifa_addr is sa, and calls
+ * in_ifadown() to remove all routes corresponding to that address. It also
+ * receives the PRC_IFUP messages from if_up() and reinstalls the interface
+ * routes.
*/
void
rip_ctlinput(int cmd, struct sockaddr *sa, void *vip)
@@ -534,10 +543,10 @@ rip_ctlinput(int cmd, struct sockaddr *sa, void *vip)
*/
in_ifscrub(ia->ia_ifp, ia);
/*
- * in_ifadown gets rid of all the rest of
- * the routes. This is not quite the right
- * thing to do, but at least if we are running
- * a routing process they will come back.
+ * in_ifadown gets rid of all the rest of the
+ * routes. This is not quite the right thing
+ * to do, but at least if we are running a
+ * routing process they will come back.
*/
in_ifadown(&ia->ia_ifa, 0);
break;
@@ -585,17 +594,17 @@ rip_attach(struct socket *so, int proto, struct thread *td)
error = priv_check(td, PRIV_NETINET_RAW);
if (error)
- return error;
+ return (error);
if (proto >= IPPROTO_MAX || proto < 0)
return EPROTONOSUPPORT;
error = soreserve(so, rip_sendspace, rip_recvspace);
if (error)
- return error;
+ return (error);
INP_INFO_WLOCK(&ripcbinfo);
error = in_pcballoc(so, &ripcbinfo);
if (error) {
INP_INFO_WUNLOCK(&ripcbinfo);
- return error;
+ return (error);
}
inp = (struct inpcb *)so->so_pcb;
INP_INFO_WUNLOCK(&ripcbinfo);
@@ -603,7 +612,7 @@ rip_attach(struct socket *so, int proto, struct thread *td)
inp->inp_ip_p = proto;
inp->inp_ip_ttl = ip_defttl;
INP_WUNLOCK(inp);
- return 0;
+ return (0);
}
static void
@@ -677,10 +686,11 @@ rip_disconnect(struct socket *so)
struct inpcb *inp;
if ((so->so_state & SS_ISCONNECTED) == 0)
- return ENOTCONN;
+ return (ENOTCONN);
inp = sotoinpcb(so);
KASSERT(inp != NULL, ("rip_disconnect: inp == NULL"));
+
INP_INFO_WLOCK(&ripcbinfo);
INP_WLOCK(inp);
rip_dodisconnect(so, inp);
@@ -696,7 +706,7 @@ rip_bind(struct socket *so, struct sockaddr *nam, struct thread *td)
struct inpcb *inp;
if (nam->sa_len != sizeof(*addr))
- return EINVAL;
+ return (EINVAL);
if (jailed(td->td_ucred)) {
if (addr->sin_addr.s_addr == INADDR_ANY)
@@ -710,16 +720,17 @@ rip_bind(struct socket *so, struct sockaddr *nam, struct thread *td)
(addr->sin_family != AF_INET && addr->sin_family != AF_IMPLINK) ||
(addr->sin_addr.s_addr &&
ifa_ifwithaddr((struct sockaddr *)addr) == 0))
- return EADDRNOTAVAIL;
+ return (EADDRNOTAVAIL);
inp = sotoinpcb(so);
KASSERT(inp != NULL, ("rip_bind: inp == NULL"));
+
INP_INFO_WLOCK(&ripcbinfo);
INP_WLOCK(inp);
inp->inp_laddr = addr->sin_addr;
INP_WUNLOCK(inp);
INP_INFO_WUNLOCK(&ripcbinfo);
- return 0;
+ return (0);
}
static int
@@ -729,21 +740,22 @@ rip_connect(struct socket *so, struct sockaddr *nam, struct thread *td)
struct inpcb *inp;
if (nam->sa_len != sizeof(*addr))
- return EINVAL;
+ return (EINVAL);
if (TAILQ_EMPTY(&ifnet))
- return EADDRNOTAVAIL;
+ return (EADDRNOTAVAIL);
if (addr->sin_family != AF_INET && addr->sin_family != AF_IMPLINK)
- return EAFNOSUPPORT;
+ return (EAFNOSUPPORT);
inp = sotoinpcb(so);
KASSERT(inp != NULL, ("rip_connect: inp == NULL"));
+
INP_INFO_WLOCK(&ripcbinfo);
INP_WLOCK(inp);
inp->inp_faddr = addr->sin_addr;
soisconnected(so);
INP_WUNLOCK(inp);
INP_INFO_WUNLOCK(&ripcbinfo);
- return 0;
+ return (0);
}
static int
@@ -753,10 +765,11 @@ rip_shutdown(struct socket *so)
inp = sotoinpcb(so);
KASSERT(inp != NULL, ("rip_shutdown: inp == NULL"));
+
INP_WLOCK(inp);
socantsendmore(so);
INP_WUNLOCK(inp);
- return 0;
+ return (0);
}
static int
@@ -768,23 +781,24 @@ rip_send(struct socket *so, int flags, struct mbuf *m, struct sockaddr *nam,
inp = sotoinpcb(so);
KASSERT(inp != NULL, ("rip_send: inp == NULL"));
+
/*
* Note: 'dst' reads below are unlocked.
*/
if (so->so_state & SS_ISCONNECTED) {
if (nam) {
m_freem(m);
- return EISCONN;
+ return (EISCONN);
}
dst = inp->inp_faddr.s_addr; /* Unlocked read. */
} else {
if (nam == NULL) {
m_freem(m);
- return ENOTCONN;
+ return (ENOTCONN);
}
dst = ((struct sockaddr_in *)nam)->sin_addr.s_addr;
}
- return rip_output(m, so, dst);
+ return (rip_output(m, so, dst));
}
static int
@@ -802,12 +816,12 @@ rip_pcblist(SYSCTL_HANDLER_ARGS)
if (req->oldptr == 0) {
n = ripcbinfo.ipi_count;
req->oldidx = 2 * (sizeof xig)
- + (n + n/8) * sizeof(struct xinpcb);
- return 0;
+ + (n + n/8) * sizeof(struct xinpcb);
+ return (0);
}
if (req->newptr != 0)
- return EPERM;
+ return (EPERM);
/*
* OK, now we're committed to doing something.
@@ -823,11 +837,11 @@ rip_pcblist(SYSCTL_HANDLER_ARGS)
xig.xig_sogen = so_gencnt;
error = SYSCTL_OUT(req, &xig, sizeof xig);
if (error)
- return error;
+ return (error);
inp_list = malloc(n * sizeof *inp_list, M_TEMP, M_WAITOK);
if (inp_list == 0)
- return ENOMEM;
+ return (ENOMEM);
INP_INFO_RLOCK(&ripcbinfo);
for (inp = LIST_FIRST(ripcbinfo.ipi_listhead), i = 0; inp && i < n;
@@ -862,11 +876,10 @@ rip_pcblist(SYSCTL_HANDLER_ARGS)
}
if (!error) {
/*
- * Give the user an updated idea of our state.
- * If the generation differs from what we told
- * her before, she knows that something happened
- * while we were processing this request, and it
- * might be necessary to retry.
+ * Give the user an updated idea of our state. If the
+ * generation differs from what we told her before, she knows
+ * that something happened while we were processing this
+ * request, and it might be necessary to retry.
*/
INP_INFO_RLOCK(&ripcbinfo);
xig.xig_gen = ripcbinfo.ipi_gencnt;
@@ -876,11 +889,11 @@ rip_pcblist(SYSCTL_HANDLER_ARGS)
error = SYSCTL_OUT(req, &xig, sizeof xig);
}
free(inp_list, M_TEMP);
- return error;
+ return (error);
}
SYSCTL_PROC(_net_inet_raw, OID_AUTO/*XXX*/, pcblist, CTLFLAG_RD, 0, 0,
- rip_pcblist, "S,xinpcb", "List of active raw IP sockets");
+ rip_pcblist, "S,xinpcb", "List of active raw IP sockets");
struct pr_usrreqs rip_usrreqs = {
.pru_abort = rip_abort,
diff --git a/sys/netinet6/raw_ip6.c b/sys/netinet6/raw_ip6.c
index b791872..85f9f10 100644
--- a/sys/netinet6/raw_ip6.c
+++ b/sys/netinet6/raw_ip6.c
@@ -29,7 +29,8 @@
/*-
* Copyright (c) 1982, 1986, 1988, 1993
- * The Regents of the University of California. All rights reserved.
+ * The Regents of the University of California.
+ * All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -128,9 +129,8 @@ int (*ip6_mforward)(struct ip6_hdr *, struct ifnet *, struct mbuf *);
int (*mrt6_ioctl)(int, caddr_t);
/*
- * Setup generic address and protocol structures
- * for raw_input routine, then pass them along with
- * mbuf chain.
+ * Setup generic address and protocol structures for raw_input routine, then
+ * pass them along with mbuf chain.
*/
int
rip6_input(struct mbuf **mp, int *offp, int proto)
@@ -145,9 +145,9 @@ rip6_input(struct mbuf **mp, int *offp, int proto)
rip6stat.rip6s_ipackets++;
if (faithprefix_p != NULL && (*faithprefix_p)(&ip6->ip6_dst)) {
- /* XXX send icmp6 host/port unreach? */
+ /* XXX Send icmp6 host/port unreach? */
m_freem(m);
- return IPPROTO_DONE;
+ return (IPPROTO_DONE);
}
init_sin6(&fromsa, m); /* general init */
@@ -187,7 +187,7 @@ docontinue:
if (n && ipsec6_in_reject(n, last)) {
m_freem(n);
ipsec6stat.in_polvio++;
- /* do not inject data into pcb */
+ /* Do not inject data into pcb. */
} else
#endif /* IPSEC */
if (n) {
@@ -219,7 +219,7 @@ docontinue:
m_freem(m);
ipsec6stat.in_polvio++;
ip6stat.ip6s_delivered--;
- /* do not inject data into pcb */
+ /* Do not inject data into pcb. */
INP_RUNLOCK(last);
} else
#endif /* IPSEC */
@@ -227,10 +227,10 @@ docontinue:
if (last->in6p_flags & IN6P_CONTROLOPTS ||
last->in6p_socket->so_options & SO_TIMESTAMP)
ip6_savecontrol(last, m, &opts);
- /* strip intermediate headers */
+ /* Strip intermediate headers. */
m_adj(m, *offp);
if (sbappendaddr(&last->in6p_socket->so_rcv,
- (struct sockaddr *)&fromsa, m, opts) == 0) {
+ (struct sockaddr *)&fromsa, m, opts) == 0) {
m_freem(m);
if (opts)
m_freem(opts);
@@ -247,13 +247,13 @@ docontinue:
else {
char *prvnxtp = ip6_get_prevhdr(m, *offp); /* XXX */
icmp6_error(m, ICMP6_PARAM_PROB,
- ICMP6_PARAMPROB_NEXTHEADER,
- prvnxtp - mtod(m, char *));
+ ICMP6_PARAMPROB_NEXTHEADER,
+ prvnxtp - mtod(m, char *));
}
ip6stat.ip6s_delivered--;
}
INP_INFO_RUNLOCK(&ripcbinfo);
- return IPPROTO_DONE;
+ return (IPPROTO_DONE);
}
void
@@ -280,7 +280,9 @@ rip6_ctlinput(int cmd, struct sockaddr *sa, void *d)
else if (inet6ctlerrmap[cmd] == 0)
return;
- /* if the parameter is from icmp6, decode it. */
+ /*
+ * If the parameter is from icmp6, decode it.
+ */
if (d != NULL) {
ip6cp = (struct ip6ctlparam *)d;
m = ip6cp->ip6c_m;
@@ -296,13 +298,12 @@ rip6_ctlinput(int cmd, struct sockaddr *sa, void *d)
}
(void) in6_pcbnotify(&ripcbinfo, sa, 0,
- (const struct sockaddr *)sa6_src,
- 0, cmd, cmdarg, notify);
+ (const struct sockaddr *)sa6_src, 0, cmd, cmdarg, notify);
}
/*
- * Generate IPv6 header and pass packet to ip6_output.
- * Tack on options user may have setup with control call.
+ * Generate IPv6 header and pass packet to ip6_output. Tack on options user
+ * may have setup with control call.
*/
int
#if __STDC__
@@ -350,6 +351,7 @@ rip6_output(m, va_alist)
/*
* Check and convert scope zone ID into internal form.
+ *
* XXX: we may still need to determine the zone later.
*/
if (!(so->so_state & SS_ISCONNECTED)) {
@@ -360,8 +362,8 @@ rip6_output(m, va_alist)
}
/*
- * For an ICMPv6 packet, we should know its type and code
- * to update statistics.
+ * For an ICMPv6 packet, we should know its type and code to update
+ * statistics.
*/
if (so->so_proto->pr_protocol == IPPROTO_ICMPV6) {
struct icmp6_hdr *icmp6;
@@ -408,12 +410,17 @@ rip6_output(m, va_alist)
}
ip6->ip6_dst = dstsock->sin6_addr;
- /* fill in the rest of the IPv6 header fields */
+ /*
+ * Fill in the rest of the IPv6 header fields.
+ */
ip6->ip6_flow = (ip6->ip6_flow & ~IPV6_FLOWINFO_MASK) |
- (in6p->in6p_flowinfo & IPV6_FLOWINFO_MASK);
+ (in6p->in6p_flowinfo & IPV6_FLOWINFO_MASK);
ip6->ip6_vfc = (ip6->ip6_vfc & ~IPV6_VERSION_MASK) |
- (IPV6_VERSION & IPV6_VERSION_MASK);
- /* ip6_plen will be filled in ip6_output, so not fill it here. */
+ (IPV6_VERSION & IPV6_VERSION_MASK);
+
+ /*
+ * ip6_plen will be filled in ip6_output, so not fill it here.
+ */
ip6->ip6_nxt = in6p->in6p_ip6_nxt;
ip6->ip6_hlim = in6_selecthlim(in6p, oifp);
@@ -423,7 +430,7 @@ rip6_output(m, va_alist)
int off;
u_int16_t *p;
- /* compute checksum */
+ /* Compute checksum. */
if (so->so_proto->pr_protocol == IPPROTO_ICMPV6)
off = offsetof(struct icmp6_hdr, icmp6_cksum);
else
@@ -544,22 +551,23 @@ rip6_attach(struct socket *so, int proto, struct thread *td)
inp = sotoinpcb(so);
KASSERT(inp == NULL, ("rip6_attach: inp != NULL"));
+
error = priv_check(td, PRIV_NETINET_RAW);
if (error)
- return error;
+ return (error);
error = soreserve(so, rip_sendspace, rip_recvspace);
if (error)
- return error;
+ return (error);
MALLOC(filter, struct icmp6_filter *,
sizeof(struct icmp6_filter), M_PCB, M_NOWAIT);
if (filter == NULL)
- return ENOMEM;
+ return (ENOMEM);
INP_INFO_WLOCK(&ripcbinfo);
error = in_pcballoc(so, &ripcbinfo);
if (error) {
INP_INFO_WUNLOCK(&ripcbinfo);
FREE(filter, M_PCB);
- return error;
+ return (error);
}
inp = (struct inpcb *)so->so_pcb;
INP_INFO_WUNLOCK(&ripcbinfo);
@@ -570,7 +578,7 @@ rip6_attach(struct socket *so, int proto, struct thread *td)
inp->in6p_icmp6filt = filter;
ICMP6_FILTER_SETPASSALL(inp->in6p_icmp6filt);
INP_WUNLOCK(inp);
- return 0;
+ return (0);
}
static void
@@ -621,10 +629,13 @@ rip6_close(struct socket *so)
static int
rip6_disconnect(struct socket *so)
{
- struct inpcb *inp = sotoinpcb(so);
+ struct inpcb *inp;
+
+ inp = sotoinpcb(so);
+ KASSERT(inp != NULL, ("rip6_disconnect: inp == NULL"));
if ((so->so_state & SS_ISCONNECTED) == 0)
- return ENOTCONN;
+ return (ENOTCONN);
inp->in6p_faddr = in6addr_any;
rip6_abort(so);
return (0);
@@ -633,22 +644,24 @@ rip6_disconnect(struct socket *so)
static int
rip6_bind(struct socket *so, struct sockaddr *nam, struct thread *td)
{
- struct inpcb *inp = sotoinpcb(so);
+ struct inpcb *inp;
struct sockaddr_in6 *addr = (struct sockaddr_in6 *)nam;
struct ifaddr *ia = NULL;
int error = 0;
+ inp = sotoinpcb(so);
KASSERT(inp != NULL, ("rip6_bind: inp == NULL"));
+
if (nam->sa_len != sizeof(*addr))
- return EINVAL;
+ return (EINVAL);
if (TAILQ_EMPTY(&ifnet) || addr->sin6_family != AF_INET6)
- return EADDRNOTAVAIL;
+ return (EADDRNOTAVAIL);
if ((error = sa6_embedscope(addr, ip6_use_defzone)) != 0)
- return(error);
+ return (error);
if (!IN6_IS_ADDR_UNSPECIFIED(&addr->sin6_addr) &&
(ia = ifa_ifwithaddr((struct sockaddr *)addr)) == 0)
- return EADDRNOTAVAIL;
+ return (EADDRNOTAVAIL);
if (ia &&
((struct in6_ifaddr *)ia)->ia6_flags &
(IN6_IFF_ANYCAST|IN6_IFF_NOTREADY|
@@ -660,38 +673,40 @@ rip6_bind(struct socket *so, struct sockaddr *nam, struct thread *td)
inp->in6p_laddr = addr->sin6_addr;
INP_WUNLOCK(inp);
INP_INFO_WUNLOCK(&ripcbinfo);
- return 0;
+ return (0);
}
static int
rip6_connect(struct socket *so, struct sockaddr *nam, struct thread *td)
{
- struct inpcb *inp = sotoinpcb(so);
+ struct inpcb *inp;
struct sockaddr_in6 *addr = (struct sockaddr_in6 *)nam;
struct in6_addr *in6a = NULL;
struct ifnet *ifp = NULL;
int error = 0, scope_ambiguous = 0;
+ inp = sotoinpcb(so);
KASSERT(inp != NULL, ("rip6_connect: inp == NULL"));
+
if (nam->sa_len != sizeof(*addr))
- return EINVAL;
+ return (EINVAL);
if (TAILQ_EMPTY(&ifnet))
- return EADDRNOTAVAIL;
+ return (EADDRNOTAVAIL);
if (addr->sin6_family != AF_INET6)
- return EAFNOSUPPORT;
+ return (EAFNOSUPPORT);
/*
- * Application should provide a proper zone ID or the use of
- * default zone IDs should be enabled. Unfortunately, some
- * applications do not behave as it should, so we need a
- * workaround. Even if an appropriate ID is not determined,
- * we'll see if we can determine the outgoing interface. If we
- * can, determine the zone ID based on the interface below.
+ * Application should provide a proper zone ID or the use of default
+ * zone IDs should be enabled. Unfortunately, some applications do
+ * not behave as it should, so we need a workaround. Even if an
+ * appropriate ID is not determined, we'll see if we can determine
+ * the outgoing interface. If we can, determine the zone ID based on
+ * the interface below.
*/
if (addr->sin6_scope_id == 0 && !ip6_use_defzone)
scope_ambiguous = 1;
if ((error = sa6_embedscope(addr, ip6_use_defzone)) != 0)
- return(error);
+ return (error);
INP_INFO_WLOCK(&ripcbinfo);
INP_WLOCK(inp);
@@ -710,14 +725,14 @@ rip6_connect(struct socket *so, struct sockaddr *nam, struct thread *td)
(error = in6_setscope(&addr->sin6_addr, ifp, NULL)) != 0) {
INP_WUNLOCK(inp);
INP_INFO_WUNLOCK(&ripcbinfo);
- return(error);
+ return (error);
}
inp->in6p_faddr = addr->sin6_addr;
inp->in6p_laddr = *in6a;
soisconnected(so);
INP_WUNLOCK(inp);
INP_INFO_WUNLOCK(&ripcbinfo);
- return 0;
+ return (0);
}
static int
@@ -727,30 +742,33 @@ rip6_shutdown(struct socket *so)
inp = sotoinpcb(so);
KASSERT(inp != NULL, ("rip6_shutdown: inp == NULL"));
+
INP_WLOCK(inp);
socantsendmore(so);
INP_WUNLOCK(inp);
- return 0;
+ return (0);
}
static int
rip6_send(struct socket *so, int flags, struct mbuf *m, struct sockaddr *nam,
struct mbuf *control, struct thread *td)
{
- struct inpcb *inp = sotoinpcb(so);
+ struct inpcb *inp;
struct sockaddr_in6 tmp;
struct sockaddr_in6 *dst;
int ret;
+ inp = sotoinpcb(so);
KASSERT(inp != NULL, ("rip6_send: inp == NULL"));
+
INP_INFO_WLOCK(&ripcbinfo);
- /* always copy sockaddr to avoid overwrites */
+ /* Always copy sockaddr to avoid overwrites. */
/* Unlocked read. */
if (so->so_state & SS_ISCONNECTED) {
if (nam) {
INP_INFO_WUNLOCK(&ripcbinfo);
m_freem(m);
- return EISCONN;
+ return (EISCONN);
}
/* XXX */
bzero(&tmp, sizeof(tmp));
@@ -763,12 +781,12 @@ rip6_send(struct socket *so, int flags, struct mbuf *m, struct sockaddr *nam,
if (nam == NULL) {
INP_INFO_WUNLOCK(&ripcbinfo);
m_freem(m);
- return ENOTCONN;
+ return (ENOTCONN);
}
if (nam->sa_len != sizeof(struct sockaddr_in6)) {
INP_INFO_WUNLOCK(&ripcbinfo);
m_freem(m);
- return(EINVAL);
+ return (EINVAL);
}
tmp = *(struct sockaddr_in6 *)nam;
dst = &tmp;
OpenPOWER on IntegriCloud