亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? iproute.c

?? 這是新華龍(www.xhl.xom.xn)開發的
?? C
?? 第 1 頁 / 共 2 頁
字號:
/* Lower half of IP, consisting of gateway routines
 * Includes routing and options processing code
 *
 */
#include "config.h"
#include "global.h"
#include "mbuf.h"
#include "iface.h"
#include "timer.h"
#include "internet.h"
#include "ip.h"
#include "tcp.h"
#include "netuser.h"
#include "icmp.h"
#include "rip.h"
#include "trace.h"
#include "pktdrvr.h"
#include "bootp.h"
#ifdef	IPSEC
#include "ipsec.h"
#endif

struct route *Routes[32][HASHMOD];	/* Routing table */
struct route R_default = {		/* Default route entry */
	NULL, NULL,
	0,0,0,
	RIP_INFINITY		/* Init metric to infinity */
};

static struct rt_cache Rt_cache[HASHMOD];
int32 Rtlookups;
int32 Rtchits;

static int q_pkt(struct iface *iface,int32 gateway,struct ip *ip,
	struct mbuf **bpp,int ckgood);

/* Initialize modulo lookup table used by hash_ip() in pcgen.asm */
void
ipinit(void)
{
	int i;

	for(i=0;i<256;i++)
		Hashtab[i] = i % HASHMOD;
}

/* Route an IP datagram. This is the "hopper" through which all IP datagrams,
 * coming or going, must pass.
 *
 * "rxbroadcast" is set to indicate that the packet came in on a subnet
 * broadcast. The router will kick the packet upstairs regardless of the
 * IP destination address.
 */
int
ip_route(
struct iface *i_iface,	/* Input interface */
struct mbuf **bpp,	/* Input packet */
int rxbroadcast		/* True if packet had link broadcast address */
){
	struct ip ip;			/* IP header being processed */
	uint16 ip_len;			/* IP header length */
	uint16 length;			/* Length of data portion */
	int32 gateway;			/* Gateway IP address */
	register struct route *rp;	/* Route table entry */
	struct iface *iface;		/* Output interface, possibly forwarded */
	uint16 offset;			/* Starting offset of current datagram */
	uint16 mf_flag;			/* Original datagram MF flag */
	int strict = 0;			/* Strict source routing flag */
	uint16 opt_len;		/* Length of current option */
	uint8 *opt;		/* -> beginning of current option */
	int i;
	int ckgood = IP_CS_OLD; /* Has good checksum without modification */
	int pointer;		/* Relative pointer index for sroute/rroute */

	if(i_iface != NULL){
		ipInReceives++;	/* Not locally generated */
		i_iface->iprecvcnt++;
	}
	if(len_p(*bpp) < IPLEN){
		/* The packet is shorter than a legal IP header */
		ipInHdrErrors++;
		free_p(bpp);
		return -1;
	}
	/* Sneak a peek at the IP header's IHL field to find its length */
	ip_len = ((*bpp)->data[0] & 0xf) << 2;
	if(ip_len < IPLEN){
		/* The IP header length field is too small */
		ipInHdrErrors++;
		free_p(bpp);
		return -1;
	}
	if(cksum(NULL,*bpp,ip_len) != 0){
		/* Bad IP header checksum; discard */
		ipInHdrErrors++;
		free_p(bpp);
		return -1;
	}
	/* Extract IP header */
	ntohip(&ip,bpp);

	if(ip.version != IPVERSION){
		/* We can't handle this version of IP */
		ipInHdrErrors++;
		free_p(bpp);
		return -1;
	}
	/* If we're running low on memory, return a source quench */
	if(!rxbroadcast && availmem() != 0)
		icmp_output(&ip,*bpp,ICMP_QUENCH,0,NULL);

	/* Process options, if any. Also compute length of secondary IP
	 * header in case fragmentation is needed later
	 */
	strict = 0;
	for(i=0;i<ip.optlen;i += opt_len){
		/* First check for the two special 1-byte options */
		switch(ip.options[i] & OPT_NUMBER){
		case IP_EOL:
			goto no_opt;	/* End of options list, we're done */
		case IP_NOOP:
			opt_len = 1;
			continue;	/* No operation, skip to next option */
		}
		/* Not a 1-byte option, so ensure that there's at least
		 * two bytes of option left, that the option length is
		 * at least two, and that there's enough space left for
		 * the specified option length.
		 */
		if(ip.optlen - i < 2
		 || ((opt_len = ip.options[i+1]) < 2)
		 || ip.optlen - i < opt_len){
			/* Truncated option, send ICMP and drop packet */
			if(!rxbroadcast){
				union icmp_args icmp_args;

				icmp_args.pointer = IPLEN + i;
				icmp_output(&ip,*bpp,ICMP_PARAM_PROB,0,&icmp_args);
			}
			free_p(bpp);
			return -1;
		}
		opt = &ip.options[i];

		switch(opt[0] & OPT_NUMBER){
		case IP_SSROUTE:	/* Strict source route & record route */
			strict = 1;	/* note fall-thru */
		case IP_LSROUTE:	/* Loose source route & record route */
			/* Source routes are ignored unless we're in the
			 * destination field
			 */
			if(opt_len < 3){
				/* Option is too short to be a legal sroute.
				 * Send an ICMP message and drop it.
				 */
				if(!rxbroadcast){
					union icmp_args icmp_args;

					icmp_args.pointer = IPLEN + i;
					icmp_output(&ip,*bpp,ICMP_PARAM_PROB,0,&icmp_args);
				}
				free_p(bpp);
				return -1;
			}
			if(ismyaddr(ip.dest) == NULL)
				break;	/* Skip to next option */
			pointer = opt[2];
			if(pointer + 4 > opt_len)
				break;	/* Route exhausted; it's for us */

			/* Put address for next hop into destination field,
			 * put our address into the route field, and bump
			 * the pointer. We've already ensured enough space.
			 */
			ip.dest = get32(&opt[pointer]);
			put32(&opt[pointer],locaddr(ip.dest));
			opt[2] += 4;
			ckgood = IP_CS_NEW;
			break;
		case IP_RROUTE:	/* Record route */
			if(opt_len < 3){
				/* Option is too short to be a legal rroute.
				 * Send an ICMP message and drop it.
				 */
				if(!rxbroadcast){
					union icmp_args icmp_args;

					icmp_args.pointer = IPLEN + i;
					icmp_output(&ip,*bpp,ICMP_PARAM_PROB,0,&icmp_args);
				}
				free_p(bpp);
				return -1;
			}				
			pointer = opt[2];
			if(pointer + 4 > opt_len){
				/* Route area exhausted; send an ICMP msg */
				if(!rxbroadcast){
					union icmp_args icmp_args;

					icmp_args.pointer = IPLEN + i;
					icmp_output(&ip,*bpp,ICMP_PARAM_PROB,0,&icmp_args);
				}
				/* Also drop if odd-sized */
				if(pointer != opt_len){
					free_p(bpp);
					return -1;
				}
			} else {
				/* Add our address to the route.
				 * We've already ensured there's enough space.
				 */
				put32(&opt[pointer],locaddr(ip.dest));
	 			opt[2] += 4;
				ckgood = IP_CS_NEW;
			}
			break;
		}
	}
no_opt:

	/* See if it's a broadcast or addressed to us, and kick it upstairs */
	if(ismyaddr(ip.dest) != NULL || rxbroadcast ||
		(WantBootp && bootp_validPacket(&ip, *bpp))){
#ifdef	GWONLY
	/* We're only a gateway, we have no host level protocols */
		if(!rxbroadcast)
			icmp_output(&ip,*bpp,ICMP_DEST_UNREACH,
			 ICMP_PROT_UNREACH,NULL);
		ipInUnknownProtos++;
		free_p(bpp);
#else
		ip_recv(i_iface,&ip,bpp,rxbroadcast,0);
#endif
		return 0;
	}
	/* Packet is not destined to us. If it originated elsewhere, count
	 * it as a forwarded datagram.
	 */
	if(i_iface != NULL)
		ipForwDatagrams++;

	/* Adjust the header checksum to allow for the modified TTL */		
	ip.checksum += 0x100;
	if((ip.checksum & 0xff00) == 0)
		ip.checksum++;	/* end-around carry */

	/* Decrement TTL and discard if zero. We don't have to check
	 * rxbroadcast here because it's already been checked
	 */
	if(--ip.ttl == 0){
		/* Send ICMP "Time Exceeded" message */
		icmp_output(&ip,*bpp,ICMP_TIME_EXCEED,0,NULL);
		ipInHdrErrors++;
		free_p(bpp);
		return -1;
	}
	/* Look up target address in routing table */
	if((rp = rt_lookup(ip.dest)) == NULL){
		/* No route exists, return unreachable message (we already
		 * know this can't be a broadcast)
		 */
		icmp_output(&ip,*bpp,ICMP_DEST_UNREACH,ICMP_HOST_UNREACH,NULL);
		free_p(bpp);
		ipOutNoRoutes++;
		return -1;
	}
	rp->uses++;

	/* Check for output forwarding and divert if necessary */
	iface = rp->iface;
	if(iface->forw != NULL)
		iface = iface->forw;

	/* Find gateway; zero gateway in routing table means "send direct" */
	if(rp->gateway == 0)
		gateway = ip.dest;
	else
		gateway = rp->gateway;

	if(strict && gateway != ip.dest){
		/* Strict source routing requires a direct entry
		 * Again, we know this isn't a broadcast
		 */
		icmp_output(&ip,*bpp,ICMP_DEST_UNREACH,ICMP_ROUTE_FAIL,NULL);
		free_p(bpp);
		ipOutNoRoutes++;
		return -1;
	}
#ifdef	IPSEC
	if(sec_output(iface,&ip,bpp) != 0){
		/* We inserted a security header, recompute hdr checksum */
		ckgood = IP_CS_NEW;	/* Recompute IP checksum */
	}
#endif
	if(ip.length <= iface->mtu){
		/* Datagram smaller than interface MTU; put header
		 * back on and send normally.
		 */
		return q_pkt(iface,gateway,&ip,bpp,ckgood);
	}
	/* Fragmentation needed */
	if(ip.flags.df){
		/* Don't Fragment set; return ICMP message and drop */
		union icmp_args icmp_args;

		icmp_args.mtu = iface->mtu;
		icmp_output(&ip,*bpp,ICMP_DEST_UNREACH,ICMP_FRAG_NEEDED,&icmp_args);
		free_p(bpp);
		ipFragFails++;
		return -1;
	}
	/* Create fragments */
	offset = ip.offset;		/* Remember starting offset */
	mf_flag = ip.flags.mf;		/* Save original MF flag */
	length = ip.length - ip_len;	/* Length of data portion */
	while(length != 0){		/* As long as there's data left */
		uint16 fragsize;		/* Size of this fragment's data */
		struct mbuf *f_data;	/* Data portion of fragment */

		/* After the first fragment, should remove those
		 * options that aren't supposed to be copied on fragmentation
		 */
		if(length + ip_len <= iface->mtu){
			/* Last fragment; send all that remains */
			fragsize = length;
			ip.flags.mf = mf_flag;	/* Pass original MF flag */
		} else {
			/* More to come, so send multiple of 8 bytes */
			fragsize = (iface->mtu - ip_len) & 0xfff8;
			ip.flags.mf = 1;
		}
		ip.length = fragsize + ip_len;

		/* Duplicate the fragment */
		dup_p(&f_data,*bpp,ip.offset-offset,fragsize);
		if(f_data == NULL){
			free_p(bpp);
			ipFragFails++;
			return -1;
		}
		if(q_pkt(iface,gateway,&ip,&f_data,IP_CS_NEW) == -1){
			free_p(bpp);
			ipFragFails++;
			return -1;
		}
		ipFragCreates++;
		ip.offset += fragsize;
		length -= fragsize;
	}
	ipFragOKs++;
	free_p(bpp);
	return 0;
}
/* Direct IP input routine for packets without link-level header */
void
ip_proc(
struct iface *iface,
struct mbuf **bpp
){
	ip_route(iface,bpp,0);
}

/* Add an IP datagram to an interface output queue, sorting first by
 * the precedence field in the IP header, and secondarily by an
 * "interactive" flag set by peeking at the transport layer to see
 * if the packet belongs to what appears to be an interactive session.
 * A layer violation, yes, but a useful one...
 */
static int
q_pkt(
struct iface *iface,
int32 gateway,
struct ip *ip,
struct mbuf **bpp,
int ckgood
){
	struct mbuf *tlast,*tbp;
	struct tcp tcp;
	struct qhdr qhdr,qtmp;
	int i;

	iface->ipsndcnt++;
	htonip(ip,bpp,ckgood);

	/* create priority field consisting of tos with 2 unused
	 * low order bits stripped, one of which we'll use as an
	 * "interactive" flag.
	 */
	qhdr.tos = (ip->tos & 0xfc);

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲免费av高清| 91网站在线播放| 成人18视频日本| 在线电影一区二区三区| 国产亚洲精品7777| 日本亚洲电影天堂| 欧美在线看片a免费观看| 国产日韩欧美激情| 蜜桃91丨九色丨蝌蚪91桃色| 色婷婷香蕉在线一区二区| 久久中文字幕电影| 午夜精品一区在线观看| 99精品欧美一区| 欧美国产一区视频在线观看| 免费观看91视频大全| 欧美专区亚洲专区| 亚洲婷婷在线视频| 国产精品一区二区不卡| 日韩欧美卡一卡二| 日本不卡一区二区三区高清视频| 欧洲色大大久久| 亚洲老司机在线| 91免费看视频| 亚洲欧美一区二区视频| 成人av电影在线网| 中文字幕国产一区二区| 国产美女精品一区二区三区| 精品日韩欧美一区二区| 美女任你摸久久| 日韩一区二区三区视频| 日本人妖一区二区| 在线电影一区二区三区| 日韩和欧美的一区| 日韩一区二区三区电影在线观看| 三级不卡在线观看| 91精品麻豆日日躁夜夜躁| 婷婷开心激情综合| 欧美一卡2卡三卡4卡5免费| 日韩影院精彩在线| 精品国产一区二区在线观看| 韩国理伦片一区二区三区在线播放| 日韩情涩欧美日韩视频| 九色|91porny| 国产午夜精品一区二区| 波多野结衣中文字幕一区 | 欧美系列一区二区| 一区二区高清免费观看影视大全| 欧美影院一区二区| 视频在线在亚洲| 日韩三级精品电影久久久| 精品综合久久久久久8888| 久久久久久久av麻豆果冻| 国产大陆精品国产| 亚洲男人的天堂在线aⅴ视频| 91麻豆自制传媒国产之光| 亚洲午夜久久久久久久久电影网 | 欧美美女黄视频| 精品一区二区av| 国产精品美女久久久久aⅴ| 91麻豆精东视频| 日韩高清不卡在线| 国产欧美一区二区三区沐欲| 91在线小视频| 免费视频最近日韩| 国产精品美女久久福利网站| 欧美日韩在线直播| 九九热在线视频观看这里只有精品| 欧美激情综合网| 在线观看视频一区二区| 久草热8精品视频在线观看| 亚洲国产成人午夜在线一区| 欧美色爱综合网| 懂色av噜噜一区二区三区av| 亚洲成人在线观看视频| 久久久一区二区| 欧亚一区二区三区| 国产成人精品亚洲777人妖| 亚洲va国产天堂va久久en| 久久人人超碰精品| 欧美日韩亚洲国产综合| 国产91露脸合集magnet| 日本在线不卡视频| 亚洲欧美另类图片小说| xfplay精品久久| 欧美男人的天堂一二区| 国产91综合网| 久久成人精品无人区| 亚洲综合色在线| 久久久久国产精品免费免费搜索| 欧美午夜电影一区| 成人福利电影精品一区二区在线观看| 热久久国产精品| 洋洋av久久久久久久一区| 日本一区二区高清| 欧美xxx久久| 欧美日韩国产综合视频在线观看| 成人h动漫精品| 国产精品一区三区| 九色|91porny| 久久福利资源站| 韩国精品久久久| 首页综合国产亚洲丝袜| 亚洲一区二区三区中文字幕在线| 国产精品美女久久久久高潮| 国产亚洲一本大道中文在线| 日韩美女一区二区三区四区| 欧美日韩成人综合| 欧美在线视频不卡| 欧美综合视频在线观看| 97se亚洲国产综合自在线| 国产不卡高清在线观看视频| 国产一区高清在线| 久久91精品久久久久久秒播| 久久99蜜桃精品| 精品一区二区av| 国产综合色精品一区二区三区| 毛片av中文字幕一区二区| 日韩专区在线视频| 理论电影国产精品| 韩国欧美国产一区| 懂色一区二区三区免费观看| 国产99精品在线观看| 成人午夜激情片| 91在线观看一区二区| 91视频免费播放| 欧美亚洲免费在线一区| 欧美欧美欧美欧美首页| 欧美一级欧美三级在线观看| 日韩欧美久久一区| 国产欧美精品国产国产专区| 亚洲国产成人一区二区三区| 国产精品理伦片| 亚洲最新视频在线观看| 亚洲高清三级视频| 久久精品国产精品亚洲红杏| 麻豆91在线播放免费| 精东粉嫩av免费一区二区三区| 国产精品一区二区不卡| 日本韩国精品在线| 日韩一区二区在线看片| 国产午夜亚洲精品羞羞网站| **欧美大码日韩| 亚洲sss视频在线视频| 精品在线你懂的| 91在线免费视频观看| 欧美日韩国产三级| 久久人人超碰精品| 亚洲自拍偷拍图区| 精品一区二区免费| 色哟哟一区二区| 日韩视频一区二区三区在线播放| 国产午夜精品理论片a级大结局 | 午夜精品在线看| 麻豆91在线观看| 91亚洲国产成人精品一区二区三| 88在线观看91蜜桃国自产| 一区二区三区在线免费播放| 亚洲.国产.中文慕字在线| 国产精品一色哟哟哟| 欧美日韩一区二区电影| 久久蜜臀精品av| 午夜久久久影院| 波多野洁衣一区| 日韩午夜av一区| 一区二区三区加勒比av| 国产一区二区精品久久99| 精品视频在线免费| 国产人妖乱国产精品人妖| 日韩福利电影在线观看| av电影一区二区| 欧美精品一区二区三区高清aⅴ| 亚洲欧美视频在线观看| 国产尤物一区二区在线| 在线观看91av| 亚洲一区二区四区蜜桃| 成人综合激情网| 日韩精品一区二| 日韩专区中文字幕一区二区| 一本大道久久精品懂色aⅴ| 精品国产不卡一区二区三区| 婷婷久久综合九色综合绿巨人| 99久久国产综合精品色伊 | 欧美精品1区2区3区| 自拍偷自拍亚洲精品播放| 国产精品亚洲一区二区三区妖精| 69av一区二区三区| 亚洲一区二区三区自拍| 99精品视频一区| 国产精品网站在线播放| 国产麻豆成人传媒免费观看| 在线观看91精品国产麻豆| 亚洲一区二区高清| 在线精品视频一区二区| 国产精品美女久久久久久| 盗摄精品av一区二区三区| 久久品道一品道久久精品| 国产一区二区按摩在线观看| 日韩免费一区二区| 九色porny丨国产精品| 精品国产亚洲在线|