version 1.3.4.1, 1993/09/24 08:54:56 |
version 1.11, 1994/02/02 05:59:04 |
|
|
* $Id$ |
* $Id$ |
*/ |
*/ |
|
|
#include "param.h" |
#include <sys/param.h> |
#include "systm.h" |
#include <sys/systm.h> |
#include "malloc.h" |
#include <sys/malloc.h> |
#include "mbuf.h" |
#include <sys/mbuf.h> |
#include "domain.h" |
#include <sys/domain.h> |
#include "protosw.h" |
#include <sys/protosw.h> |
#include "socket.h" |
#include <sys/socket.h> |
#include "errno.h" |
#include <sys/errno.h> |
#include "time.h" |
#include <sys/time.h> |
#include "kernel.h" |
#include <sys/kernel.h> |
|
|
#include "machine/cpu.h" |
#include <net/if.h> |
|
#include <net/route.h> |
#include "../net/if.h" |
|
#include "../net/route.h" |
#include <netinet/in.h> |
|
#include <netinet/in_systm.h> |
#include "in.h" |
#include <netinet/ip.h> |
#include "in_systm.h" |
#include <netinet/in_pcb.h> |
#include "ip.h" |
#include <netinet/in_var.h> |
#include "in_pcb.h" |
#include <netinet/ip_var.h> |
#include "in_var.h" |
#include <netinet/ip_icmp.h> |
#include "ip_var.h" |
#include <netinet/ip_mroute.h> |
#include "ip_icmp.h" |
|
|
|
#ifndef IPFORWARDING |
#ifndef IPFORWARDING |
#ifdef GATEWAY |
#ifdef GATEWAY |
Line 100 extern int if_index; |
|
Line 99 extern int if_index; |
|
u_long *ip_ifmatrix; |
u_long *ip_ifmatrix; |
#endif |
#endif |
|
|
|
static void ip_forward __P((struct mbuf *, int)); |
|
static void save_rte __P((u_char *, struct in_addr)); |
|
|
/* |
/* |
* IP initialization: fill in IP protocol switch table. |
* IP initialization: fill in IP protocol switch table. |
* All protocols not implemented in kernel go to raw IP protocol handler. |
* All protocols not implemented in kernel go to raw IP protocol handler. |
*/ |
*/ |
|
void |
ip_init() |
ip_init() |
{ |
{ |
register struct protosw *pr; |
register struct protosw *pr; |
Line 137 struct route ipforward_rt; |
|
Line 140 struct route ipforward_rt; |
|
* Ip input routine. Checksum and byte swap header. If fragmented |
* Ip input routine. Checksum and byte swap header. If fragmented |
* try to reassemble. Process options. Pass to next level. |
* try to reassemble. Process options. Pass to next level. |
*/ |
*/ |
|
void |
ipintr() |
ipintr() |
{ |
{ |
register struct ip *ip; |
register struct ip *ip; |
|
|
goto ours; |
goto ours; |
} |
} |
} |
} |
|
if (IN_MULTICAST(ntohl(ip->ip_dst.s_addr))) { |
|
struct in_multi *inm; |
|
#ifdef MROUTING |
|
extern struct socket *ip_mrouter; |
|
|
|
if (m->m_flags & M_EXT) { |
|
if ((m = m_pullup(m, hlen)) == 0) { |
|
ipstat.ips_toosmall++; |
|
goto next; |
|
} |
|
ip = mtod(m, struct ip *); |
|
} |
|
|
|
if (ip_mrouter) { |
|
/* |
|
* If we are acting as a multicast router, all |
|
* incoming multicast packets are passed to the |
|
* kernel-level multicast forwarding function. |
|
* The packet is returned (relatively) intact; if |
|
* ip_mforward() returns a non-zero value, the packet |
|
* must be discarded, else it may be accepted below. |
|
* |
|
* (The IP ident field is put in the same byte order |
|
* as expected when ip_mforward() is called from |
|
* ip_output().) |
|
*/ |
|
ip->ip_id = htons(ip->ip_id); |
|
if (ip_mforward(ip, m->m_pkthdr.rcvif, m) != 0) { |
|
m_freem(m); |
|
goto next; |
|
} |
|
ip->ip_id = ntohs(ip->ip_id); |
|
|
|
/* |
|
* The process-level routing demon needs to receive |
|
* all multicast IGMP packets, whether or not this |
|
* host belongs to their destination groups. |
|
*/ |
|
if (ip->ip_p == IPPROTO_IGMP) |
|
goto ours; |
|
} |
|
#endif |
|
/* |
|
* See if we belong to the destination multicast group on the |
|
* arrival interface. |
|
*/ |
|
IN_LOOKUP_MULTI(ip->ip_dst, m->m_pkthdr.rcvif, inm); |
|
if (inm == NULL) { |
|
m_freem(m); |
|
goto next; |
|
} |
|
goto ours; |
|
} |
if (ip->ip_dst.s_addr == (u_long)INADDR_BROADCAST) |
if (ip->ip_dst.s_addr == (u_long)INADDR_BROADCAST) |
goto ours; |
goto ours; |
if (ip->ip_dst.s_addr == INADDR_ANY) |
if (ip->ip_dst.s_addr == INADDR_ANY) |
|
|
* Free a fragment reassembly header and all |
* Free a fragment reassembly header and all |
* associated datagrams. |
* associated datagrams. |
*/ |
*/ |
|
void |
ip_freef(fp) |
ip_freef(fp) |
struct ipq *fp; |
struct ipq *fp; |
{ |
{ |
|
|
* Put an ip fragment on a reassembly chain. |
* Put an ip fragment on a reassembly chain. |
* Like insque, but pointers in middle of structure. |
* Like insque, but pointers in middle of structure. |
*/ |
*/ |
|
void |
ip_enq(p, prev) |
ip_enq(p, prev) |
register struct ipasfrag *p, *prev; |
register struct ipasfrag *p, *prev; |
{ |
{ |
|
|
/* |
/* |
* To ip_enq as remque is to insque. |
* To ip_enq as remque is to insque. |
*/ |
*/ |
|
void |
ip_deq(p) |
ip_deq(p) |
register struct ipasfrag *p; |
register struct ipasfrag *p; |
{ |
{ |
|
|
* if a timer expires on a reassembly |
* if a timer expires on a reassembly |
* queue, discard it. |
* queue, discard it. |
*/ |
*/ |
|
void |
ip_slowtimo() |
ip_slowtimo() |
{ |
{ |
register struct ipq *fp; |
register struct ipq *fp; |
|
|
/* |
/* |
* Drain off all datagram fragments. |
* Drain off all datagram fragments. |
*/ |
*/ |
|
void |
ip_drain() |
ip_drain() |
{ |
{ |
|
|
Line 587 struct in_ifaddr *ip_rtaddr(); |
|
Line 649 struct in_ifaddr *ip_rtaddr(); |
|
* Returns 1 if packet has been forwarded/freed, |
* Returns 1 if packet has been forwarded/freed, |
* 0 if the packet should be processed further. |
* 0 if the packet should be processed further. |
*/ |
*/ |
|
int |
ip_dooptions(m) |
ip_dooptions(m) |
struct mbuf *m; |
struct mbuf *m; |
{ |
{ |
|
|
} else |
} else |
return (0); |
return (0); |
bad: |
bad: |
icmp_error(m, type, code); |
{ |
|
register struct in_addr foo = {}; |
|
icmp_error(m, type, code, foo); |
|
} |
return (1); |
return (1); |
} |
} |
|
|
|
|
* Save incoming source route for use in replies, |
* Save incoming source route for use in replies, |
* to be picked up later by ip_srcroute if the receiver is interested. |
* to be picked up later by ip_srcroute if the receiver is interested. |
*/ |
*/ |
|
static void |
save_rte(option, dst) |
save_rte(option, dst) |
u_char *option; |
u_char *option; |
struct in_addr dst; |
struct in_addr dst; |
|
|
if (m == 0) |
if (m == 0) |
return ((struct mbuf *)0); |
return ((struct mbuf *)0); |
|
|
#define OPTSIZ (sizeof(ip_srcrt.nop) + sizeof(ip_srcrt.srcopt)) |
#define OPTSIZ (sizeof(ip_srcrt.nop) + sizeof(ip_srcrt.srcopt)) |
|
|
/* length is (nhops+1)*sizeof(addr) + sizeof(nop + srcrt header) */ |
/* length is (nhops+1)*sizeof(addr) + sizeof(nop + srcrt header) */ |
m->m_len = ip_nhops * sizeof(struct in_addr) + sizeof(struct in_addr) + |
m->m_len = ip_nhops * sizeof(struct in_addr) + sizeof(struct in_addr) + |
|
|
* will be moved, and return value is their length. |
* will be moved, and return value is their length. |
* XXX should be deleted; last arg currently ignored. |
* XXX should be deleted; last arg currently ignored. |
*/ |
*/ |
|
void |
ip_stripoptions(m, mopt) |
ip_stripoptions(m, mopt) |
register struct mbuf *m; |
register struct mbuf *m; |
struct mbuf *mopt; |
struct mbuf *mopt; |
Line 932 u_char inetctlerrmap[PRC_NCMDS] = { |
|
Line 1000 u_char inetctlerrmap[PRC_NCMDS] = { |
|
* The srcrt parameter indicates whether the packet is being forwarded |
* The srcrt parameter indicates whether the packet is being forwarded |
* via a source route. |
* via a source route. |
*/ |
*/ |
|
static void |
ip_forward(m, srcrt) |
ip_forward(m, srcrt) |
struct mbuf *m; |
struct mbuf *m; |
int srcrt; |
int srcrt; |
Line 1036 ip_forward(m, srcrt) |
|
Line 1105 ip_forward(m, srcrt) |
|
} |
} |
} |
} |
|
|
error = ip_output(m, (struct mbuf *)0, &ipforward_rt, IP_FORWARDING); |
error = ip_output(m, NULL, &ipforward_rt, IP_FORWARDING |
|
#ifdef DIRECTED_BROADCAST |
|
| IP_ALLOWBROADCAST |
|
#endif |
|
, NULL); |
if (error) |
if (error) |
ipstat.ips_cantforward++; |
ipstat.ips_cantforward++; |
else { |
else { |