-/* $NetBSD: if_ether.c,v 1.27 1995/08/12 23:59:29 mycroft Exp $ */
+/* $OpenBSD: if_ether.c,v 1.4 1996/03/03 22:30:24 niklas Exp $ */
+/* $NetBSD: if_ether.c,v 1.28 1996/02/13 23:40:59 christos Exp $ */
/*
* Copyright (c) 1982, 1986, 1988, 1993
#include <sys/errno.h>
#include <sys/ioctl.h>
#include <sys/syslog.h>
+#include <sys/proc.h>
#include <net/if.h>
#include <net/if_dl.h>
static int revarp_in_progress = 0;
static struct ifnet *myip_ifp = NULL;
+static void arptimer __P((void *));
+static void arprequest __P((struct arpcom *, u_int32_t *, u_int32_t *,
+ u_int8_t *));
+static void in_arpinput __P((struct mbuf *));
+static void arptfree __P((struct llinfo_arp *));
+static struct llinfo_arp *arplookup __P((u_int32_t, int, int ));
+#ifdef DDB
+static void db_print_sa __P((struct sockaddr *));
+static void db_print_ifa __P((struct ifaddr *));
+static void db_print_llinfo __P((caddr_t));
+static int db_show_radix_node __P((struct radix_node *, void *));
+#endif
+
/*
* Timeout routine. Age arp_tab entries periodically.
*/
if (rt)
la = (struct llinfo_arp *)rt->rt_llinfo;
else {
- if (la = arplookup(SIN(dst)->sin_addr.s_addr, 1, 0))
+ if ((la = arplookup(SIN(dst)->sin_addr.s_addr, 1, 0)) != NULL)
rt = la->la_rt;
}
if (la == 0 || rt == 0) {
struct mbuf *m;
{
struct arphdr *ar;
- int op, s;
if (m->m_len < sizeof(struct arphdr))
goto out;
*
* Note: also supports ARP via RARP packets, per the RFC.
*/
+void
in_revarpinput(m)
struct mbuf *m;
{
struct ifnet *ifp;
struct ether_arp *ar;
- int op, s;
+ int op;
ar = mtod(m, struct ether_arp *);
op = ntohs(ar->arp_op);
\f
#ifdef DDB
+
+#include <machine/db_machdep.h>
+#include <ddb/db_interface.h>
+#include <ddb/db_output.h>
static void
db_print_sa(sa)
struct sockaddr *sa;
* Function to print all the route trees.
* Use this from ddb: "call db_show_arptab"
*/
+int
db_show_arptab()
{
struct radix_node_head *rnh;
-/* $NetBSD: if_ether.h,v 1.20 1995/06/12 00:47:27 mycroft Exp $ */
+/* $OpenBSD: if_ether.h,v 1.2 1996/03/03 22:30:25 niklas Exp $ */
+/* $NetBSD: if_ether.h,v 1.21 1996/02/13 23:41:17 christos Exp $ */
/*
* Copyright (c) 1982, 1986, 1993
(step).e_enm = (ac)->ac_multiaddrs.lh_first; \
ETHER_NEXT_MULTI((step), (enm)); \
}
+
+#ifdef _KERNEL
+
+void arp_rtrequest __P((int, struct rtentry *, struct sockaddr *));
+void arpwhohas __P((struct arpcom *, struct in_addr *));
+int arpresolve __P((struct arpcom *, struct rtentry *, struct mbuf *,
+ struct sockaddr *, u_char *));
+void arpintr __P((void));
+int arpioctl __P((u_long, caddr_t));
+void arp_ifinit __P((struct arpcom *, struct ifaddr *));
+void revarpinput __P((struct mbuf *));
+void in_revarpinput __P((struct mbuf *));
+void revarprequest __P((struct ifnet *));
+int revarpwhoarewe __P((struct ifnet *, struct in_addr *, struct in_addr *));
+int revarpwhoami __P((struct in_addr *, struct ifnet *));
+int db_show_arptab __P((void));
+
+#endif
-/* $NetBSD: igmp.c,v 1.14 1995/08/12 23:59:31 mycroft Exp $ */
+/* $OpenBSD: igmp.c,v 1.2 1996/03/03 22:30:26 niklas Exp $ */
+/* $NetBSD: igmp.c,v 1.15 1996/02/13 23:41:25 christos Exp $ */
/*
* Internet Group Management Protocol (IGMP) routines.
#include <sys/mbuf.h>
#include <sys/socket.h>
#include <sys/protosw.h>
+#include <sys/systm.h>
#include <net/if.h>
#include <net/route.h>
#include <netinet/igmp.h>
#include <netinet/igmp_var.h>
+#include <machine/stdarg.h>
+
#define IP_MULTICASTOPTS 0
int igmp_timers_are_running;
static struct router_info *rti_head;
void igmp_sendpkt __P((struct in_multi *, int));
+static int rti_fill __P((struct in_multi *));
+static struct router_info * rti_find __P((struct ifnet *));
void
igmp_init()
}
void
-igmp_input(m, iphlen)
- register struct mbuf *m;
- register int iphlen;
+#if __STDC__
+igmp_input(struct mbuf *m, ...)
+#else
+igmp_input(m, va_alist)
+ struct mbuf *m;
+ va_dcl
+#endif
{
+ register int iphlen;
register struct ifnet *ifp = m->m_pkthdr.rcvif;
register struct ip *ip = mtod(m, struct ip *);
register struct igmp *igmp;
struct router_info *rti;
register struct in_ifaddr *ia;
int timer;
+ va_list ap;
+
+ va_start(ap, m);
+ iphlen = va_arg(ap, int);
+ va_end(ap);
++igmpstat.igps_rcv_total;
-/* $NetBSD: igmp_var.h,v 1.8 1995/05/31 06:08:24 mycroft Exp $ */
+/* $OpenBSD: igmp_var.h,v 1.2 1996/03/03 22:30:27 niklas Exp $ */
+/* $NetBSD: igmp_var.h,v 1.9 1996/02/13 23:41:31 christos Exp $ */
/*
* Copyright (c) 1988 Stephen Deering.
#define IGMP_RANDOM_DELAY(X) (random() % (X) + 1)
void igmp_init __P((void));
-void igmp_input __P((struct mbuf *, int));
+void igmp_input __P((struct mbuf *, ...));
void igmp_joingroup __P((struct in_multi *));
void igmp_leavegroup __P((struct in_multi *));
void igmp_fasttimo __P((void));
-/* $NetBSD: in.c,v 1.25 1995/08/12 23:59:32 mycroft Exp $ */
+/* $OpenBSD: in.c,v 1.2 1996/03/03 22:30:28 niklas Exp $ */
+/* $NetBSD: in.c,v 1.26 1996/02/13 23:41:39 christos Exp $ */
/*
* Copyright (c) 1982, 1986, 1991, 1993
#include <sys/malloc.h>
#include <sys/socket.h>
#include <sys/socketvar.h>
+#include <sys/systm.h>
#include <net/if.h>
#include <net/route.h>
#include <netinet/in_var.h>
#include <netinet/if_ether.h>
#include <netinet/ip_mroute.h>
+#include <netinet/igmp_var.h>
#include "ether.h"
{
register struct ifreq *ifr = (struct ifreq *)data;
register struct in_ifaddr *ia = 0;
- register struct ifaddr *ifa;
struct in_aliasreq *ifra = (struct in_aliasreq *)data;
struct sockaddr_in oldaddr;
int error, hostIsNew, maskIsNew;
{
register u_int32_t i = sin->sin_addr.s_addr;
struct sockaddr_in oldaddr;
- int s = splimp(), flags = RTF_UP, error, ether_output();
+ int s = splimp(), flags = RTF_UP, error;
oldaddr = ia->ia_addr;
ia->ia_addr = *sin;
/*
* Delete a multicast address record.
*/
-int
+void
in_delmulti(inm)
register struct in_multi *inm;
{
-/* $NetBSD: in.h,v 1.17 1995/06/04 05:06:55 mycroft Exp $ */
+/* $OpenBSD: in.h,v 1.5 1996/03/03 22:30:29 niklas Exp $ */
+/* $NetBSD: in.h,v 1.20 1996/02/13 23:41:47 christos Exp $ */
/*
* Copyright (c) 1982, 1986, 1990, 1993
* on these macros not doing byte-swapping.
*/
#ifdef _KERNEL
-#define __IPADDR(x) htonl((u_int32_t)(x))
+#define __IPADDR(x) ((u_int32_t) htonl((u_int32_t)(x)))
#else
#define __IPADDR(x) ((u_int32_t)(x))
#endif
#ifdef notyet
#define IPCTL_DEFMTU 4 /* default MTU */
#endif
-#define IPCTL_SOURCEROUTE 5 /* may perform source routes */
-#define IPCTL_MAXID 6
+#define IPCTL_SOURCEROUTE 5 /* may perform source routes */
+#define IPCTL_DIRECTEDBCAST 6 /* default broadcast behavior */
+#define IPCTL_MAXID 7
#define IPCTL_NAMES { \
{ 0, 0 }, \
{ "ttl", CTLTYPE_INT }, \
{ "mtu", CTLTYPE_INT }, \
{ "sourceroute", CTLTYPE_INT }, \
+ { "directed-broadcast", CTLTYPE_INT }, \
}
-/* $NetBSD: in_pcb.c,v 1.23 1995/08/17 02:57:27 mycroft Exp $ */
+/* $OpenBSD: in_pcb.c,v 1.2 1996/03/03 22:30:31 niklas Exp $ */
+/* $NetBSD: in_pcb.c,v 1.25 1996/02/13 23:41:53 christos Exp $ */
/*
* Copyright (c) 1982, 1986, 1991, 1993
struct in_addr zeroin_addr;
+#define INPCBHASH(table, faddr, fport, laddr, lport) \
+ &(table)->inpt_hashtbl[(ntohl((faddr)->s_addr) + ntohs((fport)) + ntohs((lport))) & (table->inpt_hash)]
+
void
-in_pcbinit(table)
+in_pcbinit(table, hashsize)
struct inpcbtable *table;
+ int hashsize;
{
CIRCLEQ_INIT(&table->inpt_queue);
+ table->inpt_hashtbl = hashinit(hashsize, M_PCB, &table->inpt_hash);
table->inpt_lastport = 0;
}
int
-in_pcballoc(so, table)
+in_pcballoc(so, v)
struct socket *so;
- struct inpcbtable *table;
+ void *v;
{
+ struct inpcbtable *table = v;
register struct inpcb *inp;
+ int s;
MALLOC(inp, struct inpcb *, sizeof(*inp), M_PCB, M_WAITOK);
if (inp == NULL)
bzero((caddr_t)inp, sizeof(*inp));
inp->inp_table = table;
inp->inp_socket = so;
+ s = splnet();
CIRCLEQ_INSERT_HEAD(&table->inpt_queue, inp, inp_queue);
+ LIST_INSERT_HEAD(INPCBHASH(table, &inp->inp_faddr, inp->inp_fport,
+ &inp->inp_laddr, inp->inp_lport), inp, inp_hash);
+ splx(s);
so->so_pcb = inp;
return (0);
}
int
-in_pcbbind(inp, nam)
- register struct inpcb *inp;
+in_pcbbind(v, nam)
+ register void *v;
struct mbuf *nam;
{
+ register struct inpcb *inp = v;
register struct socket *so = inp->inp_socket;
register struct inpcbtable *table = inp->inp_table;
register struct sockaddr_in *sin;
} while (in_pcblookup(table,
zeroin_addr, 0, inp->inp_laddr, lport, wild));
inp->inp_lport = lport;
+ in_pcbrehash(inp);
return (0);
}
* then pick one.
*/
int
-in_pcbconnect(inp, nam)
- register struct inpcb *inp;
+in_pcbconnect(v, nam)
+ register void *v;
struct mbuf *nam;
{
+ register struct inpcb *inp = v;
struct in_ifaddr *ia;
- struct sockaddr_in *ifaddr;
+ struct sockaddr_in *ifaddr = NULL;
register struct sockaddr_in *sin = mtod(nam, struct sockaddr_in *);
if (nam->m_len != sizeof (*sin))
}
ifaddr = satosin(&ia->ia_addr);
}
- if (in_pcblookup(inp->inp_table,
- sin->sin_addr,
- sin->sin_port,
+ if (in_pcbhashlookup(inp->inp_table, sin->sin_addr, sin->sin_port,
inp->inp_laddr.s_addr ? inp->inp_laddr : ifaddr->sin_addr,
- inp->inp_lport,
- 0))
+ inp->inp_lport) != 0)
return (EADDRINUSE);
if (inp->inp_laddr.s_addr == INADDR_ANY) {
if (inp->inp_lport == 0)
}
inp->inp_faddr = sin->sin_addr;
inp->inp_fport = sin->sin_port;
+ in_pcbrehash(inp);
return (0);
}
-int
-in_pcbdisconnect(inp)
- struct inpcb *inp;
+void
+in_pcbdisconnect(v)
+ void *v;
{
+ struct inpcb *inp = v;
inp->inp_faddr.s_addr = INADDR_ANY;
inp->inp_fport = 0;
+ in_pcbrehash(inp);
if (inp->inp_socket->so_state & SS_NOFDREF)
in_pcbdetach(inp);
}
-int
-in_pcbdetach(inp)
- struct inpcb *inp;
+void
+in_pcbdetach(v)
+ void *v;
{
+ struct inpcb *inp = v;
struct socket *so = inp->inp_socket;
+ int s;
so->so_pcb = 0;
sofree(so);
if (inp->inp_route.ro_rt)
rtfree(inp->inp_route.ro_rt);
ip_freemoptions(inp->inp_moptions);
+ s = splnet();
+ LIST_REMOVE(inp, inp_hash);
CIRCLEQ_REMOVE(&inp->inp_table->inpt_queue, inp, inp_queue);
+ splx(s);
FREE(inp, M_PCB);
}
-int
+void
in_setsockaddr(inp, nam)
register struct inpcb *inp;
struct mbuf *nam;
sin->sin_addr = inp->inp_laddr;
}
-int
+void
in_setpeeraddr(inp, nam)
struct inpcb *inp;
struct mbuf *nam;
* routing information. If the route was created dynamically
* (by a redirect), time to try a default gateway again.
*/
-int
+void
in_losing(inp)
struct inpcb *inp;
{
if (inp->inp_lport != lport)
continue;
wildcard = 0;
- if (inp->inp_laddr.s_addr != INADDR_ANY) {
- if (laddr.s_addr == INADDR_ANY)
- wildcard++;
- else if (inp->inp_laddr.s_addr != laddr.s_addr)
- continue;
- } else {
- if (laddr.s_addr != INADDR_ANY)
- wildcard++;
- }
if (inp->inp_faddr.s_addr != INADDR_ANY) {
if (faddr.s_addr == INADDR_ANY)
wildcard++;
if (faddr.s_addr != INADDR_ANY)
wildcard++;
}
+ if (inp->inp_laddr.s_addr != INADDR_ANY) {
+ if (laddr.s_addr == INADDR_ANY)
+ wildcard++;
+ else if (inp->inp_laddr.s_addr != laddr.s_addr)
+ continue;
+ } else {
+ if (laddr.s_addr != INADDR_ANY)
+ wildcard++;
+ }
if (wildcard && (flags & INPLOOKUP_WILDCARD) == 0)
continue;
if (wildcard < matchwild) {
}
return (match);
}
+
+void
+in_pcbrehash(inp)
+ struct inpcb *inp;
+{
+ struct inpcbtable *table = inp->inp_table;
+ int s;
+
+ s = splnet();
+ LIST_REMOVE(inp, inp_hash);
+ LIST_INSERT_HEAD(INPCBHASH(table, &inp->inp_faddr, inp->inp_fport,
+ &inp->inp_laddr, inp->inp_lport), inp, inp_hash);
+ splx(s);
+}
+
+#ifdef DIAGNOSTIC
+int in_pcbnotifymiss = 0;
+#endif
+
+struct inpcb *
+in_pcbhashlookup(table, faddr, fport_arg, laddr, lport_arg)
+ struct inpcbtable *table;
+ struct in_addr faddr, laddr;
+ u_int fport_arg, lport_arg;
+{
+ struct inpcbhead *head;
+ register struct inpcb *inp;
+ u_int16_t fport = fport_arg, lport = lport_arg;
+
+ head = INPCBHASH(table, &faddr, fport, &laddr, lport);
+ for (inp = head->lh_first; inp != NULL; inp = inp->inp_hash.le_next) {
+ if (inp->inp_faddr.s_addr == faddr.s_addr &&
+ inp->inp_fport == fport &&
+ inp->inp_lport == lport &&
+ inp->inp_laddr.s_addr == laddr.s_addr) {
+ /*
+ * Move this PCB to the head of hash chain so that
+ * repeated accesses are quicker. This is analogous to
+ * the historic single-entry PCB cache.
+ */
+ if (inp != head->lh_first) {
+ LIST_REMOVE(inp, inp_hash);
+ LIST_INSERT_HEAD(head, inp, inp_hash);
+ }
+ break;
+ }
+ }
+#ifdef DIAGNOSTIC
+ if (inp == NULL && in_pcbnotifymiss) {
+ printf("in_pcbhashlookup: faddr=%08x fport=%d laddr=%08x lport=%d\n",
+ ntohl(faddr.s_addr), ntohs(fport),
+ ntohl(laddr.s_addr), ntohs(lport));
+ }
+#endif
+ return (inp);
+}
-/* $NetBSD: in_pcb.h,v 1.12 1995/06/18 20:01:13 cgd Exp $ */
+/* $OpenBSD: in_pcb.h,v 1.2 1996/03/03 22:30:32 niklas Exp $ */
+/* $NetBSD: in_pcb.h,v 1.14 1996/02/13 23:42:00 christos Exp $ */
/*
* Copyright (c) 1982, 1986, 1990, 1993
* control block.
*/
struct inpcb {
+ LIST_ENTRY(inpcb) inp_hash;
CIRCLEQ_ENTRY(inpcb) inp_queue;
struct inpcbtable *inp_table;
struct in_addr inp_faddr; /* foreign host table entry */
};
struct inpcbtable {
- CIRCLEQ_HEAD(inpcbhead, inpcb) inpt_queue;
+ CIRCLEQ_HEAD(, inpcb) inpt_queue;
+ LIST_HEAD(inpcbhead, inpcb) *inpt_hashtbl;
+ u_long inpt_hash;
u_int16_t inpt_lastport;
};
#define sotoinpcb(so) ((struct inpcb *)(so)->so_pcb)
#ifdef _KERNEL
-int in_losing __P((struct inpcb *));
-int in_pcballoc __P((struct socket *, struct inpcbtable *));
-int in_pcbbind __P((struct inpcb *, struct mbuf *));
-int in_pcbconnect __P((struct inpcb *, struct mbuf *));
-int in_pcbdetach __P((struct inpcb *));
-int in_pcbdisconnect __P((struct inpcb *));
-void in_pcbinit __P((struct inpcbtable *));
+void in_losing __P((struct inpcb *));
+int in_pcballoc __P((struct socket *, void *));
+int in_pcbbind __P((void *, struct mbuf *));
+int in_pcbconnect __P((void *, struct mbuf *));
+void in_pcbdetach __P((void *));
+void in_pcbdisconnect __P((void *));
+struct inpcb *
+ in_pcbhashlookup __P((struct inpcbtable *, struct in_addr,
+ u_int, struct in_addr, u_int));
+void in_pcbinit __P((struct inpcbtable *, int));
struct inpcb *
in_pcblookup __P((struct inpcbtable *,
struct in_addr, u_int, struct in_addr, u_int, int));
u_int, struct in_addr, u_int, int, void (*)(struct inpcb *, int)));
void in_pcbnotifyall __P((struct inpcbtable *, struct sockaddr *,
int, void (*)(struct inpcb *, int)));
+void in_pcbrehash __P((struct inpcb *));
void in_rtchange __P((struct inpcb *, int));
-int in_setpeeraddr __P((struct inpcb *, struct mbuf *));
-int in_setsockaddr __P((struct inpcb *, struct mbuf *));
+void in_setpeeraddr __P((struct inpcb *, struct mbuf *));
+void in_setsockaddr __P((struct inpcb *, struct mbuf *));
#endif
-/* $NetBSD: in_proto.c,v 1.12 1995/09/30 07:02:00 thorpej Exp $ */
+/* $OpenBSD: in_proto.c,v 1.2 1996/03/03 22:30:33 niklas Exp $ */
+/* $NetBSD: in_proto.c,v 1.13 1996/02/13 23:42:09 christos Exp $ */
/*
* Copyright (c) 1982, 1986, 1993
*/
#ifdef NSIP
-void idpip_input(), nsip_ctlinput();
+#include <netns/ns_var.h>
+#include <netns/idp_var.h>
#endif /* NSIP */
#ifdef TPIP
-void tpip_input(), tpip_ctlinput(), tp_init(), tp_slowtimo(), tp_drain();
-int tp_ctloutput(), tp_usrreq();
+#include <netiso/tp_param.h>
+#include <netiso/tp_var.h>
#endif /* TPIP */
#ifdef EON
-void eoninput(), eonctlinput(), eonprotoinit();
+#include <netiso/eonvar.h>
#endif /* EON */
#ifdef MROUTING
-void ipip_input();
+#include <netinet/mroute.h>
#endif /* MROUTING */
extern struct domain inetdomain;
-/* $NetBSD: in_var.h,v 1.15 1995/06/12 00:47:37 mycroft Exp $ */
+/* $OpenBSD: in_var.h,v 1.2 1996/03/03 22:30:34 niklas Exp $ */
+/* $NetBSD: in_var.h,v 1.16 1996/02/13 23:42:15 christos Exp $ */
/*
* Copyright (c) 1985, 1986, 1993
int in_ifinit __P((struct ifnet *,
struct in_ifaddr *, struct sockaddr_in *, int));
struct in_multi *in_addmulti __P((struct in_addr *, struct ifnet *));
-int in_delmulti __P((struct in_multi *));
+void in_delmulti __P((struct in_multi *));
void in_ifscrub __P((struct ifnet *, struct in_ifaddr *));
int in_control __P((struct socket *, u_long, caddr_t, struct ifnet *));
#endif
-/* $NetBSD: ip_icmp.c,v 1.18 1995/06/12 00:47:39 mycroft Exp $ */
+/* $OpenBSD: ip_icmp.c,v 1.3 1996/03/03 22:30:35 niklas Exp $ */
+/* $NetBSD: ip_icmp.c,v 1.19 1996/02/13 23:42:22 christos Exp $ */
/*
* Copyright (c) 1982, 1986, 1988, 1993
#include <sys/socket.h>
#include <sys/time.h>
#include <sys/kernel.h>
+#include <sys/proc.h>
+
+#include <vm/vm.h>
+#include <sys/sysctl.h>
#include <net/if.h>
#include <net/route.h>
#include <netinet/in_var.h>
#include <netinet/ip.h>
#include <netinet/ip_icmp.h>
+#include <netinet/ip_var.h>
#include <netinet/icmp_var.h>
+#include <machine/stdarg.h>
+
/*
* ICMP routines: error generation, receive packet processing, and
* routines to turnaround packets back to the originator, and
* Process a received ICMP message.
*/
void
-icmp_input(m, hlen)
- register struct mbuf *m;
- int hlen;
+#if __STDC__
+icmp_input(struct mbuf *m, ...)
+#else
+icmp_input(m, va_alist)
+ struct mbuf *m;
+ va_dcl
+#endif
{
register struct icmp *icp;
register struct ip *ip = mtod(m, struct ip *);
int icmplen = ip->ip_len;
register int i;
struct in_ifaddr *ia;
- void (*ctlfunc) __P((int, struct sockaddr *, struct ip *));
+ void *(*ctlfunc) __P((int, struct sockaddr *, void *));
int code;
extern u_char ip_protox[];
+ int hlen;
+ va_list ap;
+
+ va_start(ap, m);
+ hlen = va_arg(ap, int);
+ va_end(ap);
/*
* Locate icmp structure in mbuf, and check
printf("deliver to protocol %d\n", icp->icmp_ip.ip_p);
#endif
icmpsrc.sin_addr = icp->icmp_ip.ip_dst;
- if (ctlfunc = inetsw[ip_protox[icp->icmp_ip.ip_p]].pr_ctlinput)
+ ctlfunc = inetsw[ip_protox[icp->icmp_ip.ip_p]].pr_ctlinput;
+ if (ctlfunc)
(*ctlfunc)(code, sintosa(&icmpsrc), &icp->icmp_ip);
break;
register struct ip *ip = mtod(m, struct ip *);
register struct in_ifaddr *ia;
struct in_addr t;
- struct mbuf *opts = 0, *ip_srcroute();
+ struct mbuf *opts = 0;
int optlen = (ip->ip_hl << 2) - sizeof(struct ip);
if (!in_canforward(ip->ip_src) &&
}
}
/* Terminate & pad, if necessary */
- if (cnt = opts->m_len % 4) {
+ if ((cnt = opts->m_len % 4) != 0) {
for (; cnt < 4; cnt++) {
*(mtod(opts, caddr_t) + opts->m_len) =
IPOPT_EOL;
-/* $NetBSD: ip_icmp.h,v 1.9 1995/04/17 05:32:57 cgd Exp $ */
+/* $OpenBSD: ip_icmp.h,v 1.2 1996/03/03 22:30:36 niklas Exp $ */
+/* $NetBSD: ip_icmp.h,v 1.10 1996/02/13 23:42:28 christos Exp $ */
/*
* Copyright (c) 1982, 1986, 1993
#ifdef _KERNEL
void icmp_error __P((struct mbuf *, int, int, n_long, struct ifnet *));
-void icmp_input __P((struct mbuf *, int));
+void icmp_input __P((struct mbuf *, ...));
void icmp_reflect __P((struct mbuf *));
void icmp_send __P((struct mbuf *, struct mbuf *));
int icmp_sysctl __P((int *, u_int, void *, size_t *, void *, size_t));
-/* $NetBSD: ip_input.c,v 1.25 1995/11/21 01:07:34 cgd Exp $ */
+/* $OpenBSD: ip_input.c,v 1.9 1996/03/03 22:30:37 niklas Exp $ */
+/* $NetBSD: ip_input.c,v 1.28 1996/02/13 23:42:37 christos Exp $ */
/*
* Copyright (c) 1982, 1986, 1988, 1993
#include <sys/time.h>
#include <sys/kernel.h>
#include <sys/syslog.h>
+#include <sys/proc.h>
+
+#include <vm/vm.h>
+#include <sys/sysctl.h>
#include <net/if.h>
#include <net/route.h>
#ifndef IPSENDREDIRECTS
#define IPSENDREDIRECTS 1
#endif
+/*
+ * Note: DIRECTED_BROADCAST is handled this way so that previous
+ * configuration using this option will Just Work.
+ */
+#ifndef IPDIRECTEDBCAST
+#ifdef DIRECTED_BROADCAST
+#define IPDIRECTEDBCAST 1
+#else
+#define IPDIRECTEDBCAST 0
+#endif /* DIRECTED_BROADCAST */
+#endif /* IPDIRECTEDBCAST */
int ipforwarding = IPFORWARDING;
int ipsendredirects = IPSENDREDIRECTS;
-int ip_dosourceroute = 0; /* no source routing unless sysctl'd to enable */
+int ip_dosourceroute = 0; /* no src-routing unless sysctl'd to enable */
int ip_defttl = IPDEFTTL;
+int ip_directedbcast = IPDIRECTEDBCAST;
#ifdef DIAGNOSTIC
int ipprintfs = 0;
#endif
int ipqmaxlen = IFQ_MAXLEN;
struct in_ifaddrhead in_ifaddr;
struct ifqueue ipintrq;
-#if defined(IPFILTER) || defined(IPFILTER_LKM)
-int (*fr_checkp) __P((struct ip *, int, struct ifnet *, int, struct mbuf **));
-#endif
char *
inet_ntoa(ina)
}
ip = mtod(m, struct ip *);
}
- if (ip->ip_sum = in_cksum(m, hlen)) {
+ if ((ip->ip_sum = in_cksum(m, hlen)) != 0) {
ipstat.ips_badsum++;
goto bad;
}
m_adj(m, ip->ip_len - m->m_pkthdr.len);
}
-#if defined(IPFILTER) || defined(IPFILTER_LKM)
- /*
- * Check if we want to allow this packet to be processed.
- * Consider it to be bad if not.
- */
- {
- struct mbuf *m0 = m;
- if (fr_checkp && (*fr_checkp)(ip, hlen, m->m_pkthdr.rcvif, 0, &m0))
- goto next;
- else
- ip = mtod(m = m0, struct ip *);
- }
-#endif
/*
* Process options and, if not destined for us,
* ship it on. ip_dooptions returns 1 when an
for (ia = in_ifaddr.tqh_first; ia; ia = ia->ia_list.tqe_next) {
if (ip->ip_dst.s_addr == ia->ia_addr.sin_addr.s_addr)
goto ours;
- if (
-#ifdef DIRECTED_BROADCAST
- ia->ia_ifp == m->m_pkthdr.rcvif &&
-#endif
+ if (((ip_directedbcast == 0) || (ip_directedbcast &&
+ ia->ia_ifp == m->m_pkthdr.rcvif)) &&
(ia->ia_ifp->if_flags & IFF_BROADCAST)) {
if (ip->ip_dst.s_addr == ia->ia_broadaddr.sin_addr.s_addr ||
ip->ip_dst.s_addr == ia->ia_netbroadcast.s_addr ||
ip->ip_len -= hlen;
mff = (ip->ip_off & IP_MF) != 0;
if (mff) {
- /*
- * Make sure that fragments have a data length
+ /*
+ * Make sure that fragments have a data length
* that's a non-zero multiple of 8 bytes.
- */
+ */
if (ip->ip_len == 0 || (ip->ip_len & 0x7) != 0) {
ipstat.ips_badfrags++;
goto bad;
code = &cp[IPOPT_OFFSET] - (u_char *)ip;
goto bad;
}
+
+ if (!ip_dosourceroute) {
+ char buf[4*sizeof "123"];
+
+ strcpy(buf, inet_ntoa(ip->ip_dst));
+ log(LOG_WARNING,
+ "attempted source route from %s to %s\n",
+ inet_ntoa(ip->ip_src), buf);
+ type = ICMP_UNREACH;
+ code = ICMP_UNREACH_SRCFAIL;
+ goto bad;
+ }
+
/*
* If no space remains, ignore.
*/
register struct ip *ip = mtod(m, struct ip *);
register struct sockaddr_in *sin;
register struct rtentry *rt;
- int error, type = 0, code;
+ int error, type = 0, code = 0;
struct mbuf *mcopy;
n_long dest;
struct ifnet *destifp;
#ifdef DIAGNOSTIC
if (ipprintfs)
printf("forward: src %lx dst %x ttl %x\n", ip->ip_src.s_addr,
- ip->ip_dst.s_addr, ip->ip_ttl);
+ ip->ip_dst.s_addr, ip->ip_ttl);
#endif
if (m->m_flags & M_BCAST || in_canforward(ip->ip_dst) == 0) {
ipstat.ips_cantforward++;
code = ICMP_REDIRECT_HOST;
#ifdef DIAGNOSTIC
if (ipprintfs)
- printf("redirect (%d) to %lx\n", code, (u_int32_t)dest);
+ printf("redirect (%d) to %lx\n", code, (u_int32_t)dest);
#endif
}
}
- error = ip_output(m, (struct mbuf *)0, &ipforward_rt, IP_FORWARDING
-#ifdef DIRECTED_BROADCAST
- | IP_ALLOWBROADCAST
-#endif
- , 0);
+ error = ip_output(m, (struct mbuf *)0, &ipforward_rt,
+ (IP_FORWARDING | (ip_directedbcast ? IP_ALLOWBROADCAST : 0)), 0);
if (error)
ipstat.ips_cantforward++;
else {
return (sysctl_int(oldp, oldlenp, newp, newlen, &ip_mtu));
#endif
case IPCTL_SOURCEROUTE:
- return (sysctl_int(oldp, oldlenp, newp, newlen, &ip_dosourceroute));
+ /*
+ * Don't allow this to change in a secure environment.
+ */
+ if (securelevel > 0)
+ return (EPERM);
+ return (sysctl_int(oldp, oldlenp, newp, newlen,
+ &ip_dosourceroute));
+ case IPCTL_DIRECTEDBCAST:
+ return (sysctl_int(oldp, oldlenp, newp, newlen,
+ &ip_directedbcast));
default:
return (EOPNOTSUPP);
}
-/* $NetBSD: ip_mroute.c,v 1.24 1995/08/12 23:59:38 mycroft Exp $ */
+/* $OpenBSD: ip_mroute.c,v 1.2 1996/03/03 22:30:39 niklas Exp $ */
+/* $NetBSD: ip_mroute.c,v 1.25 1996/02/13 23:42:46 christos Exp $ */
/*
* IP multicast forwarding procedures
#include <netinet/igmp_var.h>
#include <netinet/ip_mroute.h>
+#include <machine/stdarg.h>
+
#define IP_MULTICASTOPTS 0
#define M_PULLUP(m, len) \
do { \
(m) = m_pullup((m), (len)); \
} while (0)
-static int ip_mdq();
-static void phyint_send();
-static void encap_send();
-
/*
* Globals. All but ip_mrouter and ip_mrtproto could be static,
* except for netstat or debugging purposes.
extern int rsvp_on;
#endif /* RSVP_ISI */
-static void expire_upcalls();
#define EXPIRE_TIMEOUT (hz / 4) /* 4x / second */
#define UPCALL_EXPIRE 6 /* number of timeouts */
struct pkt_queue qtable[MAXVIFS][MAXQSIZE];
-static void tbf_control __P((struct vif *, struct mbuf *, struct ip *,
- u_int32_t));
-static void tbf_queue __P((struct vif *, struct mbuf *, struct ip *));
-static void tbf_dequeue __P((struct vif *, int));
-static void tbf_process_q __P((struct vif *));
-static void tbf_reprocess_q __P((void *));
-static int tbf_dq_sel __P((struct vif *, struct ip *));
-static void tbf_send_packet __P((struct vif *, struct mbuf *));
-static void tbf_update_tokens __P((struct vif *));
-static int priority __P((struct vif *, struct ip *));
+static int get_sg_cnt __P((struct sioc_sg_req *));
+static int get_vif_cnt __P((struct sioc_vif_req *));
+static int ip_mrouter_init __P((struct socket *, struct mbuf *));
+static int get_version __P((struct mbuf *));
+static int set_assert __P((struct mbuf *));
+static int get_assert __P((struct mbuf *));
+static int add_vif __P((struct mbuf *));
+static int del_vif __P((struct mbuf *));
+static void update_mfc __P((struct mfcctl *, struct mfc *));
+static void expire_mfc __P((struct mfc *));
+static int add_mfc __P((struct mbuf *));
+#ifdef UPCALL_TIMING
+static void collate __P((struct timeval *));
+#endif
+static int del_mfc __P((struct mbuf *));
+static int socket_send __P((struct socket *, struct mbuf *,
+ struct sockaddr_in *));
+static void expire_upcalls __P((void *));
+#ifdef RSVP_ISI
+static int ip_mdq __P((struct mbuf *, struct ifnet *, struct mfc *, vifi_t));
+#else
+static int ip_mdq __P((struct mbuf *, struct ifnet *, struct mfc *));
+#endif
+static void phyint_send __P((struct ip *, struct vif *, struct mbuf *));
+static void encap_send __P((struct ip *, struct vif *, struct mbuf *));
+static void tbf_control __P((struct vif *, struct mbuf *, struct ip *,
+ u_int32_t));
+static void tbf_queue __P((struct vif *, struct mbuf *, struct ip *));
+static void tbf_process_q __P((struct vif *));
+static void tbf_dequeue __P((struct vif *, int));
+static void tbf_reprocess_q __P((void *));
+static int tbf_dq_sel __P((struct vif *, struct ip *));
+static void tbf_send_packet __P((struct vif *, struct mbuf *));
+static void tbf_update_tokens __P((struct vif *));
+static int priority __P((struct vif *, struct ip *));
/*
* 'Interfaces' associated with decapsulator (so we can tell
#ifdef UPCALL_TIMING
u_int32_t upcall_data[51];
-static void collate __P((struct timeval *));
#endif /* UPCALL_TIMING */
-static int get_sg_cnt __P((struct sioc_sg_req *));
-static int get_vif_cnt __P((struct sioc_vif_req *));
-static int ip_mrouter_init __P((struct socket *, struct mbuf *));
-static int get_version __P((struct mbuf *));
-static int set_assert __P((struct mbuf *));
-static int get_assert __P((struct mbuf *));
-static int add_vif __P((struct mbuf *));
-static void reset_vif __P((struct vif *));
-static int del_vif __P((struct mbuf *));
-static void update_mfc __P((struct mfcctl *, struct mfc *));
-static void expire_mfc __P((struct mfc *));
-static int add_mfc __P((struct mbuf *));
-static int del_mfc __P((struct mbuf *));
-
/*
* Handle MRT setsockopt commands to modify the multicast routing tables.
*/
struct mbuf *m;
{
struct mfcctl *mfccp;
- struct mfc *rt, *rt1;
- u_int32_t hash;
- vifi_t vifi;
+ struct mfc *rt;
+ u_int32_t hash = 0;
struct rtdetq *rte, *nrte;
register u_short nstl;
int s;
{
register struct ip *ip = mtod(m, struct ip *);
register struct mfc *rt;
- register struct vif *vifp;
register u_char *ipoptions;
- static struct sockproto k_igmpproto = { AF_INET, IPPROTO_IGMP };
static int srctun = 0;
- register struct mbuf *mm, *mn;
+ register struct mbuf *mm;
int s;
#ifdef RSVP_ISI
+ register struct vif *vifp;
vifi_t vifi;
#endif /* RSVP_ISI */
}
+/*ARGSUSED*/
static void
-expire_upcalls()
+expire_upcalls(v)
+ void *v;
{
int i;
int s;
register struct ip *ip = mtod(m, struct ip *);
register vifi_t vifi;
register struct vif *vifp;
- register struct mbuf *tmp;
register int plen = ntohs(ip->ip_len);
/*
* ENCAP_PROTO and a local destination address).
*/
void
-ipip_input(m, hlen)
- register struct mbuf *m;
- register int hlen;
+#if __STDC__
+ipip_input(struct mbuf *m, ...)
+#else
+ipip_input(m, va_alist)
+ struct mbuf *m;
+ va_dcl
+#endif
{
+ register int hlen;
register struct ip *ip = mtod(m, struct ip *);
register int s;
register struct ifqueue *ifq;
register struct vif *vifp;
+ va_list ap;
+
+ va_start(ap, m);
+ hlen = va_arg(ap, int);
+ va_end(ap);
if (!have_encap_tunnel) {
rip_input(m);
tbf_process_q(vifp)
register struct vif *vifp;
{
- register struct mbuf *m;
register struct pkt_queue pkt_1;
register int index = (vifp - viftable);
register int s = splsoftnet();
register struct vif *vifp;
register struct mbuf *m;
{
- register struct mbuf *mcp;
int error;
int s = splsoftnet();
register struct vif *vifp;
register struct ip *ip;
{
- register u_short port;
register int prio;
/* temporary hack; may add general packet classifier some day */
return (0);
}
+void
ip_rsvp_force_done(so)
struct socket *so;
{
return;
}
+void
rsvp_input(m, ifp)
struct mbuf *m;
struct ifnet *ifp;
-/* $NetBSD: ip_mroute.h,v 1.9 1995/05/31 21:50:43 mycroft Exp $ */
+/* $OpenBSD: ip_mroute.h,v 1.2 1996/03/03 22:30:40 niklas Exp $ */
+/* $NetBSD: ip_mroute.h,v 1.10 1996/02/13 23:42:55 christos Exp $ */
/*
* Definitions for IP multicast forwarding.
};
-int ip_mforward __P((struct mbuf *, struct ifnet *));
-int ip_mrouter_get __P((int, struct socket *, struct mbuf **));
-int ip_mrouter_set __P((int, struct socket *, struct mbuf **));
-int ip_mrouter_done __P((void));
+int ip_mrouter_set __P((int, struct socket *, struct mbuf **));
+int ip_mrouter_get __P((int, struct socket *, struct mbuf **));
+int mrt_ioctl __P((u_long, caddr_t));
+int ip_mrouter_done __P((void));
+void reset_vif __P((struct vif *));
+#ifdef RSVP_ISI
+int ip_mforward __P((struct mbuf *, struct ifnet *, struct ip_moptions *));
+int legal_vif_num __P((int));
+int ip_rsvp_vif_init __P((struct socket *, struct mbuf *));
+int ip_rsvp_vif_done __P((struct socket *, struct mbuf *));
+void ip_rsvp_force_done __P((struct socket *));
+void rsvp_input __P((struct mbuf *, struct ifnet *));
+#else
+int ip_mforward __P((struct mbuf *, struct ifnet *));
+#endif
+void ipip_input __P((struct mbuf *, ...));
#endif /* _KERNEL */
-/* $NetBSD: ip_output.c,v 1.27 1995/07/01 03:44:55 cgd Exp $ */
+/* $OpenBSD: ip_output.c,v 1.4 1996/03/03 22:30:41 niklas Exp $ */
+/* $NetBSD: ip_output.c,v 1.28 1996/02/13 23:43:07 christos Exp $ */
/*
* Copyright (c) 1982, 1986, 1988, 1990, 1993
#include <sys/protosw.h>
#include <sys/socket.h>
#include <sys/socketvar.h>
+#include <sys/systm.h>
#include <net/if.h>
#include <net/route.h>
#include <machine/mtpr.h>
#endif
+#include <machine/stdarg.h>
+
static struct mbuf *ip_insertoptions __P((struct mbuf *, struct mbuf *, int *));
static void ip_mloopback
__P((struct ifnet *, struct mbuf *, struct sockaddr_in *));
* The mbuf opt, if present, will not be freed.
*/
int
-ip_output(m0, opt, ro, flags, imo)
+#if __STDC__
+ip_output(struct mbuf *m0, ...)
+#else
+ip_output(m0, va_alist)
struct mbuf *m0;
- struct mbuf *opt;
- struct route *ro;
- int flags;
- struct ip_moptions *imo;
+ va_dcl
+#endif
{
register struct ip *ip, *mhip;
register struct ifnet *ifp;
struct route iproute;
struct sockaddr_in *dst;
struct in_ifaddr *ia;
+ struct mbuf *opt;
+ struct route *ro;
+ int flags;
+ struct ip_moptions *imo;
+ va_list ap;
+
+ va_start(ap, m0);
+ opt = va_arg(ap, struct mbuf *);
+ ro = va_arg(ap, struct route *);
+ flags = va_arg(ap, int);
+ imo = va_arg(ap, struct ip_moptions *);
+ va_end(ap);
+
+
#ifdef DIAGNOSTIC
if ((m->m_flags & M_PKTHDR) == 0)
{
register struct inpcb *inp = sotoinpcb(so);
register struct mbuf *m = *mp;
- register int optval;
+ register int optval = 0;
int error = 0;
if (level != IPPROTO_IP) {
-/* $NetBSD: ip_var.h,v 1.15 1995/11/21 01:07:38 cgd Exp $ */
+/* $OpenBSD: ip_var.h,v 1.3 1996/03/03 22:30:42 niklas Exp $ */
+/* $NetBSD: ip_var.h,v 1.16 1996/02/13 23:43:20 christos Exp $ */
/*
* Copyright (c) 1982, 1986, 1993
void ip_init __P((void));
int ip_mforward __P((struct mbuf *, struct ifnet *));
int ip_optcopy __P((struct ip *, struct ip *));
-int ip_output __P((struct mbuf *,
- struct mbuf *, struct route *, int, struct ip_moptions *));
+int ip_output __P((struct mbuf *, ...));
int ip_pcbopts __P((struct mbuf **, struct mbuf *));
struct ip *
ip_reass __P((struct ipqent *, struct ipq *));
void ipintr __P((void));
int rip_ctloutput __P((int, struct socket *, int, int, struct mbuf **));
void rip_init __P((void));
-void rip_input __P((struct mbuf *));
-int rip_output __P((struct mbuf *, struct socket *, u_long));
+void rip_input __P((struct mbuf *, ...));
+int rip_output __P((struct mbuf *, ...));
int rip_usrreq __P((struct socket *,
int, struct mbuf *, struct mbuf *, struct mbuf *));
#endif
-/* $NetBSD: raw_ip.c,v 1.22 1995/11/30 16:42:18 pk Exp $ */
+/* $OpenBSD: raw_ip.c,v 1.3 1996/03/03 22:30:43 niklas Exp $ */
+/* $NetBSD: raw_ip.c,v 1.24 1996/02/13 23:43:29 christos Exp $ */
/*
* Copyright (c) 1982, 1986, 1988, 1993
#include <netinet/ip_var.h>
#include <netinet/ip_mroute.h>
#include <netinet/in_pcb.h>
+#include <netinet/in_var.h>
+
+#include <machine/stdarg.h>
struct inpcbtable rawcbtable;
rip_init()
{
- in_pcbinit(&rawcbtable);
+ in_pcbinit(&rawcbtable, 1);
}
struct sockaddr_in ripsrc = { sizeof(ripsrc), AF_INET };
* mbuf chain.
*/
void
-rip_input(m)
+#if __STDC__
+rip_input(struct mbuf *m, ...)
+#else
+rip_input(m, va_alist)
struct mbuf *m;
+ va_dcl
+#endif
{
register struct ip *ip = mtod(m, struct ip *);
register struct inpcb *inp;
continue;
if (last) {
struct mbuf *n;
- if (n = m_copy(m, 0, (int)M_COPYALL)) {
+ if ((n = m_copy(m, 0, (int)M_COPYALL)) != NULL) {
if (sbappendaddr(&last->so_rcv,
sintosa(&ripsrc), n,
(struct mbuf *)0) == 0)
* Tack on options user may have setup with control call.
*/
int
-rip_output(m, so, dst)
- register struct mbuf *m;
+#if __STDC__
+rip_output(struct mbuf *m, ...)
+#else
+rip_output(m, va_alist)
+ struct mbuf *m;
+ va_dcl
+#endif
+{
struct socket *so;
u_long dst;
-{
register struct ip *ip;
- register struct inpcb *inp = sotoinpcb(so);
+ register struct inpcb *inp;
struct mbuf *opts;
- int flags = (so->so_options & SO_DONTROUTE) | IP_ALLOWBROADCAST;
+ int flags;
+ va_list ap;
+
+ va_start(ap, m);
+ so = va_arg(ap, struct socket *);
+ dst = va_arg(ap, u_long);
+ va_end(ap);
+
+ inp = sotoinpcb(so);
+ flags = (so->so_options & SO_DONTROUTE) | IP_ALLOWBROADCAST;
/*
* If the user handed us a complete IP packet, use it.
struct mbuf **m;
{
register struct inpcb *inp = sotoinpcb(so);
- register int error;
if (level != IPPROTO_IP) {
if (m != 0 && *m != 0)
-/* $NetBSD: tcp_debug.c,v 1.9 1995/04/13 06:36:32 cgd Exp $ */
+/* $OpenBSD: tcp_debug.c,v 1.2 1996/03/03 22:30:44 niklas Exp $ */
+/* $NetBSD: tcp_debug.c,v 1.10 1996/02/13 23:43:36 christos Exp $ */
/*
* Copyright (c) 1982, 1986, 1993
struct tcpiphdr *ti;
int req;
{
+#ifdef TCPDEBUG
tcp_seq seq, ack;
int len, flags;
+#endif
struct tcp_debug *td = &tcp_debug[tcp_debx++];
if (tcp_debx == TCP_NDEBUG)
-/* $NetBSD: tcp_input.c,v 1.20 1995/11/21 01:07:39 cgd Exp $ */
+/* $OpenBSD: tcp_input.c,v 1.3 1996/03/03 22:30:45 niklas Exp $ */
+/* $NetBSD: tcp_input.c,v 1.23 1996/02/13 23:43:44 christos Exp $ */
/*
* Copyright (c) 1982, 1986, 1988, 1990, 1993, 1994
#include <netinet/tcpip.h>
#include <netinet/tcp_debug.h>
+#include <machine/stdarg.h>
+
int tcprexmtthresh = 3;
struct tcpiphdr tcp_saveti;
-struct inpcb *tcp_last_inpcb = 0;
extern u_long sb_max;
* protocol specification dated September, 1981 very closely.
*/
void
-tcp_input(m, iphlen)
+#if __STDC__
+tcp_input(struct mbuf *m, ...)
+#else
+tcp_input(m, va_alist)
register struct mbuf *m;
- int iphlen;
+#endif
{
register struct tcpiphdr *ti;
register struct inpcb *inp;
caddr_t optp = NULL;
- int optlen;
+ int optlen = 0;
int len, tlen, off;
register struct tcpcb *tp = 0;
register int tiflags;
- struct socket *so;
+ struct socket *so = NULL;
int todrop, acked, ourfinisacked, needoutput = 0;
- short ostate;
+ short ostate = 0;
struct in_addr laddr;
int dropsocket = 0;
int iss = 0;
u_long tiwin;
u_int32_t ts_val, ts_ecr;
int ts_present = 0;
+ int iphlen;
+ va_list ap;
+
+ va_start(ap, m);
+ iphlen = va_arg(ap, int);
+ va_end(ap);
tcpstat.tcps_rcvtotal++;
/*
bzero(ti->ti_x1, sizeof ti->ti_x1);
ti->ti_len = (u_int16_t)tlen;
HTONS(ti->ti_len);
- if (ti->ti_sum = in_cksum(m, len)) {
+ if ((ti->ti_sum = in_cksum(m, len)) != 0) {
tcpstat.tcps_rcvbadsum++;
goto drop;
}
* Locate pcb for segment.
*/
findpcb:
- inp = tcp_last_inpcb;
- if (inp == 0 ||
- inp->inp_lport != ti->ti_dport ||
- inp->inp_fport != ti->ti_sport ||
- inp->inp_faddr.s_addr != ti->ti_src.s_addr ||
- inp->inp_laddr.s_addr != ti->ti_dst.s_addr) {
- ++tcpstat.tcps_pcbcachemiss;
+ inp = in_pcbhashlookup(&tcbtable, ti->ti_src, ti->ti_sport,
+ ti->ti_dst, ti->ti_dport);
+ if (inp == 0) {
+ ++tcpstat.tcps_pcbhashmiss;
inp = in_pcblookup(&tcbtable, ti->ti_src, ti->ti_sport,
ti->ti_dst, ti->ti_dport, INPLOOKUP_WILDCARD);
/*
* If the TCB exists but is in CLOSED state, it is embryonic,
* but should either do a listen or a connect soon.
*/
- if (inp == 0)
+ if (inp == 0) {
+ ++tcpstat.tcps_noport;
goto dropwithreset;
- tcp_last_inpcb = inp;
+ }
}
tp = intotcpcb(inp);
inp = (struct inpcb *)so->so_pcb;
inp->inp_laddr = ti->ti_dst;
inp->inp_lport = ti->ti_dport;
+ in_pcbrehash(inp);
#if BSD>=43
inp->inp_options = ip_srcroute();
#endif
* Update window information.
* Don't look at window if no ACK: TAC's send garbage on first SYN.
*/
- if ((tiflags & TH_ACK) &&
- (SEQ_LT(tp->snd_wl1, ti->ti_seq) || tp->snd_wl1 == ti->ti_seq &&
- (SEQ_LT(tp->snd_wl2, ti->ti_ack) ||
- tp->snd_wl2 == ti->ti_ack && tiwin > tp->snd_wnd))) {
+ if (((tiflags & TH_ACK) && SEQ_LT(tp->snd_wl1, ti->ti_seq)) ||
+ (tp->snd_wl1 == ti->ti_seq && SEQ_LT(tp->snd_wl2, ti->ti_ack)) ||
+ (tp->snd_wl2 == ti->ti_ack && tiwin > tp->snd_wnd)) {
/* keep track of pure window updates */
if (ti->ti_len == 0 &&
tp->snd_wl2 == ti->ti_ack && tiwin > tp->snd_wnd)
* but if two URG's are pending at once, some out-of-band
* data may creep in... ick.
*/
- if (ti->ti_urp <= ti->ti_len
+ if (ti->ti_urp <= (u_int16_t) ti->ti_len
#ifdef SO_OOBINLINE
&& (so->so_options & SO_OOBINLINE) == 0
#endif
* case PRU_RCVD). If a FIN has already been received on this
* connection then we just ignore the text.
*/
- if ((ti->ti_len || (tiflags&TH_FIN)) &&
+ if ((ti->ti_len || (tiflags & TH_FIN)) &&
TCPS_HAVERCVDFIN(tp->t_state) == 0) {
TCP_REASS(tp, ti, m, so, tiflags);
/*
/*
* If FIN is received ACK the FIN and let the user know
- * that the connection is closing.
+ * that the connection is closing. Ignore a FIN received before
+ * the connection is fully established.
*/
- if (tiflags & TH_FIN) {
+ if ((tiflags & TH_FIN) && TCPS_HAVEESTABLISHED(tp->t_state)) {
if (TCPS_HAVERCVDFIN(tp->t_state) == 0) {
socantrcvmore(so);
tp->t_flags |= TF_ACKNOW;
switch (tp->t_state) {
/*
- * In SYN_RECEIVED and ESTABLISHED STATES
- * enter the CLOSE_WAIT state.
+ * In ESTABLISHED STATE enter the CLOSE_WAIT state.
*/
- case TCPS_SYN_RECEIVED:
case TCPS_ESTABLISHED:
tp->t_state = TCPS_CLOSE_WAIT;
break;
/* default variation is +- 1 rtt */
tp->t_rttvar =
tp->t_srtt * TCP_RTTVAR_SCALE / TCP_RTT_SCALE;
- TCPT_RANGESET(tp->t_rxtcur,
+ TCPT_RANGESET((long) tp->t_rxtcur,
((tp->t_srtt >> 2) + tp->t_rttvar) >> 1,
tp->t_rttmin, TCPTV_REXMTMAX);
}
-/* $NetBSD: tcp_output.c,v 1.13 1995/04/13 20:09:23 cgd Exp $ */
+/* $OpenBSD: tcp_output.c,v 1.2 1996/03/03 22:30:46 niklas Exp $ */
+/* $NetBSD: tcp_output.c,v 1.14 1996/02/13 23:43:53 christos Exp $ */
/*
* Copyright (c) 1982, 1986, 1988, 1990, 1993
#include <netinet/tcpip.h>
#include <netinet/tcp_debug.h>
+#ifdef TUBA
+#include <netiso/iso.h>
+#include <netiso/tuba_table.h>
+#endif
+
#ifdef notyet
extern struct mbuf *m_copypack();
#endif
-/* $NetBSD: tcp_subr.c,v 1.20 1995/11/21 01:07:41 cgd Exp $ */
+/* $OpenBSD: tcp_subr.c,v 1.3 1996/03/03 22:30:47 niklas Exp $ */
+/* $NetBSD: tcp_subr.c,v 1.22 1996/02/13 23:44:00 christos Exp $ */
/*
* Copyright (c) 1982, 1986, 1988, 1990, 1993
int tcp_rttdflt = TCPTV_SRTTDFLT / PR_SLOWHZ;
int tcp_do_rfc1323 = 1;
-extern struct inpcb *tcp_last_inpcb;
+#ifndef TCBHASHSIZE
+#define TCBHASHSIZE 128
+#endif
+int tcbhashsize = TCBHASHSIZE;
/*
* Tcp initialization
{
tcp_iss = 1; /* wrong */
- in_pcbinit(&tcbtable);
+ in_pcbinit(&tcbtable, tcbhashsize);
if (max_protohdr < sizeof(struct tcpiphdr))
max_protohdr = sizeof(struct tcpiphdr);
if (max_linkhdr + sizeof(struct tcpiphdr) > MHLEN)
register struct ipqent *qe;
struct inpcb *inp = tp->t_inpcb;
struct socket *so = inp->inp_socket;
- register struct mbuf *m;
#ifdef RTV_RTT
register struct rtentry *rt;
if (SEQ_LT(tp->iss + so->so_snd.sb_hiwat * 16, tp->snd_max) &&
(rt = inp->inp_route.ro_rt) &&
satosin(rt_key(rt))->sin_addr.s_addr != INADDR_ANY) {
- register u_long i;
+ register u_long i = 0;
if ((rt->rt_rmx.rmx_locks & RTV_RTT) == 0) {
i = tp->t_srtt *
* before we start updating, then update on both good
* and bad news.
*/
- if ((rt->rt_rmx.rmx_locks & RTV_SSTHRESH) == 0 &&
- (i = tp->snd_ssthresh) && rt->rt_rmx.rmx_ssthresh ||
+ if (((rt->rt_rmx.rmx_locks & RTV_SSTHRESH) == 0 &&
+ (i = tp->snd_ssthresh) && rt->rt_rmx.rmx_ssthresh) ||
i < (rt->rt_rmx.rmx_sendpipe / 2)) {
/*
* convert the limit from user data bytes to
free(tp, M_PCB);
inp->inp_ppcb = 0;
soisdisconnected(so);
- /* clobber input pcb cache if we're closing the cached connection */
- if (inp == tcp_last_inpcb)
- tcp_last_inpcb = 0;
in_pcbdetach(inp);
tcpstat.tcps_closed++;
return ((struct tcpcb *)0);
sowwakeup(so);
}
-void
-tcp_ctlinput(cmd, sa, ip)
+void *
+tcp_ctlinput(cmd, sa, v)
int cmd;
struct sockaddr *sa;
- register struct ip *ip;
+ register void *v;
{
+ register struct ip *ip = v;
register struct tcphdr *th;
- extern struct in_addr zeroin_addr;
extern int inetctlerrmap[];
void (*notify) __P((struct inpcb *, int)) = tcp_notify;
int errno;
if ((unsigned)cmd >= PRC_NCMDS)
- return;
+ return NULL;
errno = inetctlerrmap[cmd];
if (cmd == PRC_QUENCH)
notify = tcp_quench;
else if (cmd == PRC_HOSTDEAD)
ip = 0;
else if (errno == 0)
- return;
+ return NULL;
if (ip) {
th = (struct tcphdr *)((caddr_t)ip + (ip->ip_hl << 2));
in_pcbnotify(&tcbtable, sa, th->th_dport, ip->ip_src,
th->th_sport, errno, notify);
} else
in_pcbnotifyall(&tcbtable, sa, errno, notify);
+ return NULL;
}
/*
-/* $NetBSD: tcp_timer.c,v 1.13 1995/08/12 23:59:39 mycroft Exp $ */
+/* $OpenBSD: tcp_timer.c,v 1.2 1996/03/03 22:30:48 niklas Exp $ */
+/* $NetBSD: tcp_timer.c,v 1.14 1996/02/13 23:44:09 christos Exp $ */
/*
* Copyright (c) 1982, 1986, 1988, 1990, 1993
}
tcpstat.tcps_rexmttimeo++;
rexmt = TCP_REXMTVAL(tp) * tcp_backoff[tp->t_rxtshift];
- TCPT_RANGESET(tp->t_rxtcur, rexmt,
+ TCPT_RANGESET((long) tp->t_rxtcur, rexmt,
tp->t_rttmin, TCPTV_REXMTMAX);
tp->t_timer[TCPT_REXMT] = tp->t_rxtcur;
/*
-/* $NetBSD: tcp_usrreq.c,v 1.17 1995/09/30 07:02:05 thorpej Exp $ */
+/* $OpenBSD: tcp_usrreq.c,v 1.2 1996/03/03 22:30:49 niklas Exp $ */
+/* $NetBSD: tcp_usrreq.c,v 1.20 1996/02/13 23:44:16 christos Exp $ */
/*
* Copyright (c) 1982, 1986, 1988, 1993
#include <sys/protosw.h>
#include <sys/errno.h>
#include <sys/stat.h>
+#include <sys/proc.h>
+#include <sys/ucred.h>
+#include <vm/vm.h>
+#include <sys/sysctl.h>
#include <net/if.h>
#include <net/route.h>
struct mbuf *m, *nam, *control;
{
register struct inpcb *inp;
- register struct tcpcb *tp;
+ register struct tcpcb *tp = NULL;
int s;
int error = 0;
int ostate;
tp->t_state = TCPS_LAST_ACK;
break;
}
- if (tp && tp->t_state >= TCPS_FIN_WAIT_2)
+ if (tp && tp->t_state >= TCPS_FIN_WAIT_2) {
soisdisconnected(tp->t_inpcb->inp_socket);
+ /*
+ * If we are in FIN_WAIT_2, we arrived here because the
+ * application did a shutdown of the send side. Like the
+ * case of a transition from FIN_WAIT_1 to FIN_WAIT_2 after
+ * a full close, we start a timer to make sure sockets are
+ * not left in FIN_WAIT_2 forever.
+ */
+ if (tp->t_state == TCPS_FIN_WAIT_2)
+ tp->t_timer[TCPT_2MSL] = tcp_maxidle;
+ }
return (tp);
}
-/* $NetBSD: tcp_var.h,v 1.15 1995/11/21 01:07:43 cgd Exp $ */
+/* $OpenBSD: tcp_var.h,v 1.3 1996/03/03 22:30:50 niklas Exp $ */
+/* $NetBSD: tcp_var.h,v 1.17 1996/02/13 23:44:24 christos Exp $ */
/*
* Copyright (c) 1982, 1986, 1993, 1994
u_long tcps_pawsdrop; /* segments dropped due to PAWS */
u_long tcps_predack; /* times hdr predict ok for acks */
u_long tcps_preddat; /* times hdr predict ok for data pkts */
- u_long tcps_pcbcachemiss;
+
+ u_long tcps_pcbhashmiss; /* input packets missing pcb hash */
+ u_long tcps_noport; /* no socket on port */
};
/*
void tcp_canceltimers __P((struct tcpcb *));
struct tcpcb *
tcp_close __P((struct tcpcb *));
-void tcp_ctlinput __P((int, struct sockaddr *, struct ip *));
+void *tcp_ctlinput __P((int, struct sockaddr *, void *));
int tcp_ctloutput __P((int, struct socket *, int, int, struct mbuf **));
struct tcpcb *
tcp_disconnect __P((struct tcpcb *));
void tcp_drain __P((void));
void tcp_fasttimo __P((void));
void tcp_init __P((void));
-void tcp_input __P((struct mbuf *, int));
+void tcp_input __P((struct mbuf *, ...));
int tcp_mss __P((struct tcpcb *, u_int));
struct tcpcb *
tcp_newtcpcb __P((struct inpcb *));
-/* $NetBSD: udp_usrreq.c,v 1.25 1995/11/21 01:07:46 cgd Exp $ */
+/* $OpenBSD: udp_usrreq.c,v 1.3 1996/03/03 22:30:51 niklas Exp $ */
+/* $NetBSD: udp_usrreq.c,v 1.27 1996/02/13 23:44:32 christos Exp $ */
/*
* Copyright (c) 1982, 1986, 1988, 1990, 1993
#include <sys/socketvar.h>
#include <sys/errno.h>
#include <sys/stat.h>
+#include <sys/systm.h>
+#include <sys/proc.h>
+
+#include <vm/vm.h>
+#include <sys/sysctl.h>
#include <net/if.h>
#include <net/route.h>
#include <netinet/udp.h>
#include <netinet/udp_var.h>
+#include <machine/stdarg.h>
+
/*
* UDP protocol implementation.
* Per RFC 768, August, 1980.
#endif
struct sockaddr_in udp_in = { sizeof(udp_in), AF_INET };
-struct inpcb *udp_last_inpcb = 0;
static void udp_detach __P((struct inpcb *));
static void udp_notify __P((struct inpcb *, int));
static struct mbuf *udp_saveopt __P((caddr_t, int, int));
+#ifndef UDBHASHSIZE
+#define UDBHASHSIZE 128
+#endif
+int udbhashsize = UDBHASHSIZE;
+
void
udp_init()
{
- in_pcbinit(&udbtable);
+ in_pcbinit(&udbtable, udbhashsize);
}
void
-udp_input(m, iphlen)
- register struct mbuf *m;
- int iphlen;
+#if __STDC__
+udp_input(struct mbuf *m, ...)
+#else
+udp_input(m, va_alist)
+ struct mbuf *m;
+ va_dcl
+#endif
{
register struct ip *ip;
register struct udphdr *uh;
struct mbuf *opts = 0;
int len;
struct ip save_ip;
+ int iphlen;
+ va_list ap;
+
+ va_start(ap, m);
+ iphlen = va_arg(ap, int);
+ va_end(ap);
udpstat.udps_ipackets++;
bzero(((struct ipovly *)ip)->ih_x1,
sizeof ((struct ipovly *)ip)->ih_x1);
((struct ipovly *)ip)->ih_len = uh->uh_ulen;
- if (uh->uh_sum = in_cksum(m, len + sizeof (struct ip))) {
+ if ((uh->uh_sum = in_cksum(m, len + sizeof (struct ip))) != 0) {
udpstat.udps_badsum++;
m_freem(m);
return;
/*
* Locate pcb for datagram.
*/
- inp = udp_last_inpcb;
- if (inp == 0 ||
- inp->inp_lport != uh->uh_dport ||
- inp->inp_fport != uh->uh_sport ||
- inp->inp_faddr.s_addr != ip->ip_src.s_addr ||
- inp->inp_laddr.s_addr != ip->ip_dst.s_addr) {
- udpstat.udpps_pcbcachemiss++;
+ inp = in_pcbhashlookup(&udbtable, ip->ip_src, uh->uh_sport,
+ ip->ip_dst, uh->uh_dport);
+ if (inp == 0) {
+ ++udpstat.udps_pcbhashmiss;
inp = in_pcblookup(&udbtable, ip->ip_src, uh->uh_sport,
ip->ip_dst, uh->uh_dport, INPLOOKUP_WILDCARD);
if (inp == 0) {
icmp_error(m, ICMP_UNREACH, ICMP_UNREACH_PORT, 0, 0);
return;
}
- udp_last_inpcb = inp;
}
/*
sowwakeup(inp->inp_socket);
}
-void
-udp_ctlinput(cmd, sa, ip)
+void *
+udp_ctlinput(cmd, sa, v)
int cmd;
struct sockaddr *sa;
- register struct ip *ip;
+ void *v;
{
+ register struct ip *ip = v;
register struct udphdr *uh;
- extern struct in_addr zeroin_addr;
extern int inetctlerrmap[];
void (*notify) __P((struct inpcb *, int)) = udp_notify;
int errno;
if ((unsigned)cmd >= PRC_NCMDS)
- return;
+ return NULL;
errno = inetctlerrmap[cmd];
if (PRC_IS_REDIRECT(cmd))
notify = in_rtchange, ip = 0;
else if (cmd == PRC_HOSTDEAD)
ip = 0;
else if (errno == 0)
- return;
+ return NULL;
if (ip) {
uh = (struct udphdr *)((caddr_t)ip + (ip->ip_hl << 2));
in_pcbnotify(&udbtable, sa, uh->uh_dport, ip->ip_src,
uh->uh_sport, errno, notify);
} else
in_pcbnotifyall(&udbtable, sa, errno, notify);
+ return NULL;
}
int
-udp_output(inp, m, addr, control)
+#if __STDC__
+udp_output(struct mbuf *m, ...)
+#else
+udp_output(m, va_alist)
+ struct mbuf *m;
+ va_dcl
+#endif
+{
register struct inpcb *inp;
- register struct mbuf *m;
struct mbuf *addr, *control;
-{
register struct udpiphdr *ui;
register int len = m->m_pkthdr.len;
struct in_addr laddr;
- int s, error = 0;
+ int s = 0, error = 0;
+ va_list ap;
+
+ va_start(ap, m);
+ inp = va_arg(ap, struct inpcb *);
+ addr = va_arg(ap, struct mbuf *);
+ control = va_arg(ap, struct mbuf *);
+ va_end(ap);
if (control)
m_freem(control); /* XXX */
break;
case PRU_SEND:
- return (udp_output(inp, m, addr, control));
+ return (udp_output(m, inp, addr, control));
case PRU_ABORT:
soisdisconnected(so);
{
int s = splsoftnet();
- if (inp == udp_last_inpcb)
- udp_last_inpcb = 0;
in_pcbdetach(inp);
splx(s);
}
/*
* Sysctl for udp variables.
*/
+int
udp_sysctl(name, namelen, oldp, oldlenp, newp, newlen)
int *name;
u_int namelen;
-/* $NetBSD: udp_var.h,v 1.10 1995/11/21 01:07:48 cgd Exp $ */
+/* $OpenBSD: udp_var.h,v 1.3 1996/03/03 22:30:52 niklas Exp $ */
+/* $NetBSD: udp_var.h,v 1.12 1996/02/13 23:44:41 christos Exp $ */
/*
* Copyright (c) 1982, 1986, 1989, 1993
u_long udps_noport; /* no socket on port */
u_long udps_noportbcast; /* of above, arrived as broadcast */
u_long udps_fullsock; /* not delivered, input socket full */
- u_long udpps_pcbcachemiss; /* input packets missing pcb cache */
+ u_long udps_pcbhashmiss; /* input packets missing pcb hash */
/* output statistics: */
u_long udps_opackets; /* total output packets */
};
struct inpcbtable udbtable;
struct udpstat udpstat;
-void udp_ctlinput __P((int, struct sockaddr *, struct ip *));
+void *udp_ctlinput __P((int, struct sockaddr *, void *));
void udp_init __P((void));
-void udp_input __P((struct mbuf *, int));
-int udp_output __P((struct inpcb *,
- struct mbuf *, struct mbuf *, struct mbuf *));
+void udp_input __P((struct mbuf *, ...));
+int udp_output __P((struct mbuf *, ...));
int udp_sysctl __P((int *, u_int, void *, size_t *, void *, size_t));
int udp_usrreq __P((struct socket *,
int, struct mbuf *, struct mbuf *, struct mbuf *));