BSD 4_1c_2 development
authorCSRG <csrg@ucbvax.Berkeley.EDU>
Thu, 4 Nov 1982 08:22:51 +0000 (00:22 -0800)
committerCSRG <csrg@ucbvax.Berkeley.EDU>
Thu, 4 Nov 1982 08:22:51 +0000 (00:22 -0800)
Work on file a/sys/net/af.h
Work on file a/sys/net/if.h
Work on file a/sys/net/raw_cb.h
Work on file a/sys/net/route.h
Work on file a/sys/net/af.c

Synthesized-from: CSRG/cd1/4.1c.2

a/sys/net/af.c [new file with mode: 0644]
a/sys/net/af.h [new file with mode: 0644]
a/sys/net/if.h [new file with mode: 0644]
a/sys/net/raw_cb.h [new file with mode: 0644]
a/sys/net/route.h [new file with mode: 0644]

diff --git a/a/sys/net/af.c b/a/sys/net/af.c
new file mode 100644 (file)
index 0000000..bdaba7a
--- /dev/null
@@ -0,0 +1,54 @@
+/*     af.c    4.7     82/10/17        */
+
+#include "../h/param.h"
+#include "../h/mbuf.h"
+#include "../h/protosw.h"
+#include "../h/socket.h"
+#include "../h/socketvar.h"
+#include "../net/af.h"
+
+/*
+ * Address family support routines
+ */
+int    null_hash(), null_netmatch();
+#define        AFNULL \
+       { null_hash,    null_netmatch }
+
+#ifdef INET
+extern int inet_hash(), inet_netmatch();
+#define        AFINET \
+       { inet_hash,    inet_netmatch }
+#else
+#define        AFINET  AFNULL
+#endif
+
+#ifdef PUP
+extern int pup_hash(), pup_netmatch();
+#define        AFPUP \
+       { pup_hash,     pup_netmatch }
+#else
+#define        AFPUP   AFNULL
+#endif
+
+struct afswitch afswitch[AF_MAX] = {
+       AFNULL, AFNULL, AFINET, AFINET, AFPUP,
+       AFNULL, AFNULL, AFNULL, AFNULL, AFNULL,
+       AFNULL
+};
+
+/*ARGSUSED*/
+null_hash(addr, hp)
+       struct sockaddr *addr;
+       struct afhash *hp;
+{
+
+       hp->afh_nethash = hp->afh_hosthash = 0;
+}
+
+/*ARGSUSED*/
+null_netmatch(a1, a2)
+       struct sockaddr *a1, *a2;
+{
+
+       return (0);
+}
diff --git a/a/sys/net/af.h b/a/sys/net/af.h
new file mode 100644 (file)
index 0000000..ab1453d
--- /dev/null
@@ -0,0 +1,29 @@
+/*     af.h    4.3     82/03/30        */
+
+/*
+ * Address family routines,
+ * used in handling generic sockaddr structures.
+ *
+ * Hash routine is called
+ *     af_hash(addr, h);
+ *     struct sockaddr *addr; struct afhash *h;
+ * producing an afhash structure for addr.
+ *
+ * Netmatch routine is called
+ *     af_netmatch(addr1, addr2);
+ * where addr1 and addr2 are sockaddr *.  Returns 1 if network
+ * values match, 0 otherwise.
+ */
+struct afswitch {
+       int     (*af_hash)();
+       int     (*af_netmatch)();
+};
+
+struct afhash {
+       u_int   afh_hosthash;
+       u_int   afh_nethash;
+};
+
+#ifdef KERNEL
+struct afswitch afswitch[];
+#endif
diff --git a/a/sys/net/if.h b/a/sys/net/if.h
new file mode 100644 (file)
index 0000000..fd639ff
--- /dev/null
@@ -0,0 +1,124 @@
+/*     if.h    4.16    82/10/31        */
+
+/*
+ * Structures defining a network interface, providing a packet
+ * transport mechanism (ala level 0 of the PUP protocols).
+ *
+ * Each interface accepts output datagrams of a specified maximum
+ * length, and provides higher level routines with input datagrams
+ * received from its medium.
+ *
+ * Output occurs when the routine if_output is called, with three parameters:
+ *     (*ifp->if_output)(ifp, m, dst)
+ * Here m is the mbuf chain to be sent and dst is the destination address.
+ * The output routine encapsulates the supplied datagram if necessary,
+ * and then transmits it on its medium.
+ *
+ * On input, each interface unwraps the data received by it, and either
+ * places it on the input queue of a internetwork datagram routine
+ * and posts the associated software interrupt, or passes the datagram to a raw
+ * packet input routine.
+ *
+ * Routines exist for locating interfaces by their addresses
+ * or for locating a interface on a certain network, as well as more general
+ * routing and gateway routines maintaining information used to locate
+ * interfaces.  These routines live in the files if.c and route.c
+ */
+
+/*
+ * Structure defining a queue for a network interface.
+ *
+ * (Would like to call this struct ``if'', but C isn't PL/1.)
+ *
+ * EVENTUALLY PURGE if_net AND if_host FROM STRUCTURE
+ */
+struct ifnet {
+       char    *if_name;               /* name, e.g. ``en'' or ``lo'' */
+       short   if_unit;                /* sub-unit for lower level driver */
+       short   if_mtu;                 /* maximum transmission unit */
+       int     if_net;                 /* network number of interface */
+       short   if_flags;               /* up/down, broadcast, etc. */
+       short   if_timer;               /* time 'til if_watchdog called */
+       int     if_host[2];             /* local net host number */
+       struct  sockaddr if_addr;       /* address of interface */
+       union {
+               struct  sockaddr ifu_broadaddr;
+               struct  sockaddr ifu_dstaddr;
+       } if_ifu;
+#define        if_broadaddr    if_ifu.ifu_broadaddr    /* broadcast address */
+#define        if_dstaddr      if_ifu.ifu_dstaddr      /* other end of p-to-p link */
+       struct  ifqueue {
+               struct  mbuf *ifq_head;
+               struct  mbuf *ifq_tail;
+               int     ifq_len;
+               int     ifq_maxlen;
+               int     ifq_drops;
+       } if_snd;                       /* output queue */
+/* procedure handles */
+       int     (*if_init)();           /* init routine */
+       int     (*if_output)();         /* output routine */
+       int     (*if_reset)();          /* bus reset routine */
+       int     (*if_watchdog)();       /* timer routine */
+/* generic interface statistics */
+       int     if_ipackets;            /* packets received on interface */
+       int     if_ierrors;             /* input errors on interface */
+       int     if_opackets;            /* packets sent on interface */
+       int     if_oerrors;             /* output errors on interface */
+       int     if_collisions;          /* collisions on csma interfaces */
+/* end statistics */
+       struct  ifnet *if_next;
+};
+
+#define        IFF_UP          0x1             /* interface is up */
+#define        IFF_BROADCAST   0x2             /* broadcast address valid */
+#define        IFF_DEBUG       0x4             /* turn on debugging */
+#define        IFF_ROUTE       0x8             /* routing entry installed */
+#define        IFF_POINTOPOINT 0x10            /* interface is point-to-point link */
+
+/*
+ * Output queues (ifp->if_snd) and internetwork datagram level (pup level 1)
+ * input routines have queues of messages stored on ifqueue structures
+ * (defined above).  Entries are added to and deleted from these structures
+ * by these macros, which should be called with ipl raised to splimp().
+ */
+#define        IF_QFULL(ifq)           ((ifq)->ifq_len >= (ifq)->ifq_maxlen)
+#define        IF_DROP(ifq)            ((ifq)->ifq_drops++)
+#define        IF_ENQUEUE(ifq, m) { \
+       (m)->m_act = 0; \
+       if ((ifq)->ifq_tail == 0) \
+               (ifq)->ifq_head = m; \
+       else \
+               (ifq)->ifq_tail->m_act = m; \
+       (ifq)->ifq_tail = m; \
+       (ifq)->ifq_len++; \
+}
+#define        IF_PREPEND(ifq, m) { \
+       (m)->m_act = (ifq)->ifq_head; \
+       if ((ifq)->ifq_tail == 0) \
+               (ifq)->ifq_tail = (m); \
+       (ifq)->ifq_head = (m); \
+       (ifq)->ifq_len++; \
+}
+#define        IF_DEQUEUE(ifq, m) { \
+       (m) = (ifq)->ifq_head; \
+       if (m) { \
+               if (((ifq)->ifq_head = (m)->m_act) == 0) \
+                       (ifq)->ifq_tail = 0; \
+               (m)->m_act = 0; \
+               (ifq)->ifq_len--; \
+       } \
+}
+
+#define        IFQ_MAXLEN      50
+#define        IFNET_SLOWHZ    1               /* granularity is 1 second */
+
+#ifdef KERNEL
+#ifdef INET
+struct ifqueue ipintrq;                /* ip packet input queue */
+#endif
+struct ifqueue rawintrq;               /* raw packet input queue */
+struct ifnet *ifnet;
+struct ifnet *if_ifwithaddr(), *if_ifwithnet(), *if_ifwithaf();
+struct ifnet *if_ifonnetof();
+struct in_addr if_makeaddr();
+#endif
diff --git a/a/sys/net/raw_cb.h b/a/sys/net/raw_cb.h
new file mode 100644 (file)
index 0000000..987424e
--- /dev/null
@@ -0,0 +1,45 @@
+/*     raw_cb.h        4.4     82/04/10        */
+
+/*
+ * Raw protocol interface control block.  Used
+ * to tie a socket to the generic raw interface.
+ */
+struct rawcb {
+       struct  rawcb *rcb_next;        /* doubly linked list */
+       struct  rawcb *rcb_prev;
+       struct  socket *rcb_socket;     /* back pointer to socket */
+       struct  sockaddr rcb_faddr;     /* destination address */
+       struct  sockaddr rcb_laddr;     /* socket's address */
+       caddr_t rcb_pcb;                /* protocol specific stuff */
+       short   rcb_flags;
+};
+
+/*
+ * Since we can't interpret canonical addresses,
+ * we mark an address present in the flags field.
+ */
+#define        RAW_LADDR       01
+#define        RAW_FADDR       02
+
+#define        sotorawcb(so)           ((struct rawcb *)(so)->so_pcb)
+
+/*
+ * Nominal space allocated to a raw socket.
+ */
+#define        RAWSNDQ         2048
+#define        RAWRCVQ         2048
+
+/*
+ * Format of raw interface header prepended by
+ * raw_input after call from protocol specific
+ * input routine.
+ */
+struct raw_header {
+       struct  sockproto raw_proto;    /* format of packet */
+       struct  sockaddr raw_dst;       /* dst address for rawintr */
+       struct  sockaddr raw_src;       /* src address for sbappendaddr */
+};
+
+#ifdef KERNEL
+struct rawcb rawcb;                    /* head of list */
+#endif
diff --git a/a/sys/net/route.h b/a/sys/net/route.h
new file mode 100644 (file)
index 0000000..bed9d6d
--- /dev/null
@@ -0,0 +1,65 @@
+/*     route.h 4.8     82/06/12        */
+
+/*
+ * Kernel resident routing tables.
+ * 
+ * The routing tables are initialized at boot time by
+ * making entries for all directly connected interfaces.
+ * Routing daemons can thereafter update the routing tables.
+ *
+ * TODO:
+ *     keep statistics
+ */
+
+/*
+ * A route consists of a destination address and a reference
+ * to a routing entry.  These are often held by protocols
+ * in their control blocks, e.g. inpcb.
+ */
+struct route {
+       struct  rtentry *ro_rt;
+       struct  sockaddr ro_dst;
+#ifdef notdef
+       caddr_t ro_pcb;                 /* not used yet */
+#endif
+};
+#ifdef KERNEL
+/*
+ * The route ``routetoif'' is a special atom passed to the output routines
+ * to implement the SO_DONTROUTE option.
+ */
+struct route routetoif;
+#endif
+
+/*
+ * We distinguish between routes to hosts and routes to networks,
+ * preferring the former if available.  For each route we infer
+ * the interface to use from the gateway address supplied when
+ * the route was entered.  Routes that forward packets through
+ * gateways are marked so that the output routines know to address the
+ * gateway rather than the ultimate destination.
+ */
+struct rtentry {
+       u_long  rt_hash;                /* to speed lookups */
+       struct  sockaddr rt_dst;        /* key */
+       struct  sockaddr rt_gateway;    /* value */
+       short   rt_flags;               /* up/down?, host/net */
+       short   rt_refcnt;              /* # held references */
+       u_long  rt_use;                 /* raw # packets forwarded */
+       struct  ifnet *rt_ifp;          /* the answer: interface to use */
+};
+#ifdef KERNEL
+#define        RTHASHSIZ       7
+struct mbuf *rthost[RTHASHSIZ];
+struct mbuf *rtnet[RTHASHSIZ];
+#endif
+
+#define        RTF_UP          0x1             /* route useable */
+#define        RTF_GATEWAY     0x2             /* destination is a gateway */
+#define        RTF_HOST        0x4             /* host entry (net otherwise) */
+
+#define        RTFREE(rt) \
+       if ((rt)->rt_refcnt == 1) \
+               rtfree(rt); \
+       else \
+               (rt)->rt_refcnt--;