Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/net KNF.



details:   https://anonhg.NetBSD.org/src/rev/da6e29e39581
branches:  trunk
changeset: 749803:da6e29e39581
user:      dyoung <dyoung%NetBSD.org@localhost>
date:      Wed Dec 09 00:44:26 2009 +0000

description:
KNF.

diffstat:

 sys/net/if_srt.c |  760 ++++++++++++++++++++++++++++--------------------------
 sys/net/if_srt.h |   36 +-
 2 files changed, 411 insertions(+), 385 deletions(-)

diffs (truncated from 908 to 300 lines):

diff -r 449a1ca3e82b -r da6e29e39581 sys/net/if_srt.c
--- a/sys/net/if_srt.c  Wed Dec 09 00:23:28 2009 +0000
+++ b/sys/net/if_srt.c  Wed Dec 09 00:44:26 2009 +0000
@@ -1,8 +1,8 @@
-/* $NetBSD: if_srt.c,v 1.11 2009/03/18 16:00:22 cegger Exp $ */
+/* $NetBSD: if_srt.c,v 1.12 2009/12/09 00:44:26 dyoung Exp $ */
 /* This file is in the public domain. */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_srt.c,v 1.11 2009/03/18 16:00:22 cegger Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_srt.c,v 1.12 2009/12/09 00:44:26 dyoung Exp $");
 
 #include "opt_inet.h"
 
@@ -15,11 +15,13 @@
 #endif
 
 /* include-file bug workarounds */
-#include <sys/types.h> /* sys/conf.h */
-#include <sys/resource.h> /* sys/resourcevar.h (uvm/uvm_param.h, sys/mbuf.h) */
-#include <netinet/in.h> /* netinet/ip.h */
-#include <sys/param.h> /* sys/mbuf.h */
-#include <netinet/in_systm.h> /* netinet/ip.h */
+#include <sys/types.h>         /* sys/conf.h */
+#include <sys/resource.h>      /* sys/resourcevar.h
+                                * (uvm/uvm_param.h, sys/mbuf.h)
+                                */
+#include <netinet/in.h>                /* netinet/ip.h */
+#include <sys/param.h>         /* sys/mbuf.h */
+#include <netinet/in_systm.h>  /* netinet/ip.h */
 
 #include <sys/conf.h>
 #include <sys/mbuf.h>
@@ -39,437 +41,461 @@
 #undef NBPFILTER
 #define NBPFILTER 0
 
-typedef struct srt_rt RT;
-typedef struct softc SOFTC;
+struct srt_softc {
+       struct ifnet intf;      /* XXX interface botch */
+       int unit;
+       int nrt;
+       struct srt_rt **rts;
+       unsigned int flags;     /* SSF_* values from if_srt.h */
+#define SSF_UCHG (SSF_MTULOCK) /* userland-changeable bits */
+       unsigned int kflags;    /* bits private to this file */
+#define SKF_CDEVOPEN 0x00000001
+};
 
-struct softc {
-  struct ifnet intf;   /* XXX interface botch */
-  int unit;
-  int nrt;
-  RT **rts;
-  unsigned int flags;  /* SSF_* values from if_srt.h */
-#define SSF_UCHG (SSF_MTULOCK) /* userland-changeable bits */
-  unsigned int kflags; /* bits private to this file */
-#define SKF_CDEVOPEN 0x00000001
-  } ;
+void srtattach(void);
 
-static SOFTC *softcv[SRT_MAXUNIT+1];
+static struct srt_softc *softcv[SRT_MAXUNIT+1];
 static unsigned int global_flags;
 
 /* Internal routines. */
 
-static unsigned int ipv4_masks[33]
- = { 0x00000000, /* /0 */
-     0x80000000, 0xc0000000, 0xe0000000, 0xf0000000, /* /1 - /4 */
-     0xf8000000, 0xfc000000, 0xfe000000, 0xff000000, /* /5 - /8 */
-     0xff800000, 0xffc00000, 0xffe00000, 0xfff00000, /* /9 - /12 */
-     0xfff80000, 0xfffc0000, 0xfffe0000, 0xffff0000, /* /13 - /16 */
-     0xffff8000, 0xffffc000, 0xffffe000, 0xfffff000, /* /17 - /20 */
-     0xfffff800, 0xfffffc00, 0xfffffe00, 0xffffff00, /* /21 - /24 */
-     0xffffff80, 0xffffffc0, 0xffffffe0, 0xfffffff0, /* /25 - /28 */
-     0xfffffff8, 0xfffffffc, 0xfffffffe, 0xffffffff  /* /29 - /32 */ };
+static unsigned int ipv4_masks[33] = {
+       0x00000000, /* /0 */
+       0x80000000, 0xc0000000, 0xe0000000, 0xf0000000, /* /1 - /4 */
+       0xf8000000, 0xfc000000, 0xfe000000, 0xff000000, /* /5 - /8 */
+       0xff800000, 0xffc00000, 0xffe00000, 0xfff00000, /* /9 - /12 */
+       0xfff80000, 0xfffc0000, 0xfffe0000, 0xffff0000, /* /13 - /16 */
+       0xffff8000, 0xffffc000, 0xffffe000, 0xfffff000, /* /17 - /20 */
+       0xfffff800, 0xfffffc00, 0xfffffe00, 0xffffff00, /* /21 - /24 */
+       0xffffff80, 0xffffffc0, 0xffffffe0, 0xfffffff0, /* /25 - /28 */
+       0xfffffff8, 0xfffffffc, 0xfffffffe, 0xffffffff  /* /29 - /32 */
+};
 
-static void update_mtu(SOFTC *sc)
+static void
+update_mtu(struct srt_softc *sc)
 {
- int mtu;
- int i;
- RT *r;
+       int mtu;
+       int i;
+       struct srt_rt *r;
 
- if (sc->flags & SSF_MTULOCK) return;
- mtu = 65535;
- for (i=sc->nrt-1;i>=0;i--)
-  { r = sc->rts[i];
-    if (r->u.dstifp->if_mtu < mtu) mtu = r->u.dstifp->if_mtu;
-  }
- sc->intf.if_mtu = mtu;
+       if (sc->flags & SSF_MTULOCK)
+               return;
+       mtu = 65535;
+       for (i=sc->nrt-1;i>=0;i--) {
+               r = sc->rts[i];
+               if (r->u.dstifp->if_mtu < mtu)
+                       mtu = r->u.dstifp->if_mtu;
+       }
+       sc->intf.if_mtu = mtu;
 }
 
-static RT *find_rt(SOFTC *sc, int af, ...)
+static struct srt_rt *
+find_rt(struct srt_softc *sc, int af, ...)
 {
- int i;
- RT *r;
- struct in_addr ia;
- struct in6_addr ia6;
- va_list ap;
+       int i;
+       struct srt_rt *r;
+       struct in_addr ia;
+       struct in6_addr ia6;
+       va_list ap;
 
- ia.s_addr = 0; ia6.s6_addr[0] = 0; /* shut up incorrect -Wuninitialized */
- va_start(ap,af);
- switch (af)
-  { case AF_INET:
-       ia = va_arg(ap,struct in_addr);
-       break;
-    case AF_INET6:
-       ia6 = va_arg(ap,struct in6_addr);
-       break;
-    default:
-       panic("if_srt find_rt: impossible address family");
-       break;
-  }
- va_end(ap);
- for (i=0;i<sc->nrt;i++)
-  { r = sc->rts[i];
-    if (r->af != af) continue;
-    switch (af)
-     { case AF_INET:
-         if ((ia.s_addr & ipv4_masks[r->srcmask]) == r->srcmatch.v4.s_addr) return(r);
-         break;
-       case AF_INET6:
-         if ((r->srcmask >= 8) && memcmp(&ia6,&r->srcmatch.v6,r->srcmask/8)) continue;
-         if ( (r->srcmask % 8) &&
-              ( ( ia6.s6_addr[r->srcmask/8] ^
-                  r->srcmatch.v6.s6_addr[r->srcmask/8] ) &
-                0xff & (0xff00 >> (r->srcmask%8)) ) ) continue;
-         return(r);
-         break;
-       default:
-         panic("if_srt find_rt: impossible address family 2");
-         break;
-     }
-  }
- return(0);
+       ia.s_addr = 0; ia6.s6_addr[0] = 0; /* shut up incorrect -Wuninitialized */
+       va_start(ap,af);
+       switch (af) {
+       case AF_INET:
+               ia = va_arg(ap,struct in_addr);
+               break;
+       case AF_INET6:
+               ia6 = va_arg(ap,struct in6_addr);
+               break;
+       default:
+               panic("if_srt find_rt: impossible address family");
+               break;
+       }
+       va_end(ap);
+       for (i=0;i<sc->nrt;i++) {
+               r = sc->rts[i];
+               if (r->af != af)
+                       continue;
+               switch (af) {
+               case AF_INET:
+                       if ((ia.s_addr & ipv4_masks[r->srcmask]) ==
+                           r->srcmatch.v4.s_addr)
+                               return r;
+                       break;
+               case AF_INET6:
+                       if ((r->srcmask >= 8) &&
+                           memcmp(&ia6,&r->srcmatch.v6,r->srcmask / 8) != 0)
+                               continue;
+                       if ((r->srcmask % 8) &&
+                           ((ia6.s6_addr[r->srcmask / 8] ^
+                            r->srcmatch.v6.s6_addr[r->srcmask / 8]) &
+                            0xff & (0xff00 >> (r->srcmask % 8))))
+                               continue;
+                       return r;
+               default:
+                       panic("if_srt find_rt: impossible address family 2");
+                       break;
+               }
+       }
+       return 0;
 }
 
 /* Network device interface. */
 
-static int srt_if_ioctl(struct ifnet *intf, u_long cmd, void *data)
+static int
+srt_if_ioctl(struct ifnet *ifp, u_long cmd, void *data)
 {
- struct ifaddr *ifa;
- int s;
- int err;
+       struct ifaddr *ifa;
+       int s;
+       int err;
 
- err = 0;
- s = splnet();
- switch (cmd)
-  { case SIOCINITIFADDR:
-    case SIOCSIFDSTADDR:
-       ifa = (void *) data;
-       switch (ifa->ifa_addr->sa_family)
-       {
+       err = 0;
+       s = splnet();
+       switch (cmd) {
+       case SIOCINITIFADDR:
+       case SIOCSIFDSTADDR:
+               ifa = (void *) data;
+               switch (ifa->ifa_addr->sa_family) {
 #ifdef INET
-         case AF_INET:
+               case AF_INET:
+                       break;
 #endif
 #ifdef INET6
-         case AF_INET6:
+               case AF_INET6:
+                       break;
 #endif
-            break;
-         default:
-            err = EAFNOSUPPORT;
-            break;
+               default:
+                       err = EAFNOSUPPORT;
+                       break;
+               }
+               /* XXX do we need to do more here for either of these? */
+               break;
+       default:
+               if ((err = ifioctl_common(ifp, cmd, data)) == ENETRESET)
+                       err = 0;
+               break;
        }
-       /* XXX do we need to do more here for either of these? */
-       break;
-    default:
-       if ((err = ifioctl_common(intf, cmd, data)) == ENETRESET)
-             err = 0;
-       break;
-  }
- splx(s);
- return(err);
+       splx(s);
+       return err;
 }
 
-static int srt_if_output(
-       struct ifnet *intf,
+static int
+srt_if_output(
+       struct ifnet *ifp,
        struct mbuf *m,
        const struct sockaddr *to,
-       struct rtentry *rtp )
+       struct rtentry *rtp)
 {
- SOFTC *sc;
- RT *r;
+       struct srt_softc *sc;
+       struct srt_rt *r;
 
- sc = intf->if_softc;
- if (! (intf->if_flags & IFF_UP))
-  { m_freem(m);
-    return(ENETDOWN);
-  }
- switch (to->sa_family)
-  {
+       sc = ifp->if_softc;



Home | Main Index | Thread Index | Old Index