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

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? iproute.c

?? TCPIP協(xié)議包
?? C
?? 第 1 頁 / 共 2 頁
字號(hào):
/* 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);

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號(hào) Ctrl + =
減小字號(hào) Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产日本欧美一区二区| 欧美三级日韩在线| 亚洲一区二区综合| 欧美精品一区二区三区一线天视频| 91天堂素人约啪| 青青草成人在线观看| 中文字幕日韩一区| 精品av久久707| 欧美日韩aaaaa| 91女神在线视频| 国产盗摄精品一区二区三区在线| 午夜在线成人av| 亚洲精品成a人| 国产精品日产欧美久久久久| 精品日产卡一卡二卡麻豆| 91电影在线观看| 成人高清视频在线观看| 国产美女精品在线| 日韩二区在线观看| 亚洲成av人综合在线观看| 亚洲美女一区二区三区| 中文字幕免费不卡| 国产欧美久久久精品影院| 欧美成人a在线| 91麻豆精品91久久久久久清纯| 欧美在线免费观看亚洲| 91免费国产在线观看| 成人99免费视频| 国产不卡在线一区| 国产精品影音先锋| 韩国三级在线一区| 狠狠色丁香婷婷综合久久片| 奇米影视7777精品一区二区| 亚洲va国产天堂va久久en| 亚洲一本大道在线| 亚洲一区二区影院| 亚洲丰满少妇videoshd| 亚洲国产精品尤物yw在线观看| 亚洲免费在线播放| 亚洲美腿欧美偷拍| 亚洲午夜三级在线| 午夜伊人狠狠久久| 男男视频亚洲欧美| 久久99这里只有精品| 国产一区二区三区在线观看精品| 久久99精品久久久久婷婷| 激情文学综合插| 国产麻豆一精品一av一免费| 国产精品一区二区久久不卡| 成人永久看片免费视频天堂| 成年人国产精品| 91福利视频久久久久| 欧美中文字幕一区| 欧美精品免费视频| 日韩午夜电影av| 久久精品欧美日韩精品| 国产精品不卡一区二区三区| 一区二区三区精品在线观看| 丝瓜av网站精品一区二区| 蜜乳av一区二区三区| 精品一区二区久久| 成人手机在线视频| 色视频成人在线观看免| 欧美人妇做爰xxxⅹ性高电影| 91精品福利在线一区二区三区| 日韩欧美国产综合在线一区二区三区| 久久综合久久综合亚洲| 国产精品久久久久久久岛一牛影视| 亚洲啪啪综合av一区二区三区| 婷婷夜色潮精品综合在线| 久久99国产精品麻豆| 99在线热播精品免费| 欧美日韩和欧美的一区二区| 精品88久久久久88久久久| 国产精品传媒在线| 日韩精品乱码av一区二区| 久久 天天综合| 91丨九色丨蝌蚪丨老版| 制服丝袜成人动漫| 国产欧美一区二区精品久导航| 伊人一区二区三区| 韩国成人福利片在线播放| 91丝袜呻吟高潮美腿白嫩在线观看| 制服丝袜亚洲色图| 亚洲天堂中文字幕| 久久国产免费看| 色婷婷亚洲精品| 精品成人一区二区三区四区| 一区二区三区国产精华| 精品亚洲欧美一区| 日韩免费视频一区| 国产精品久久久久久久久图文区| 日韩在线观看一区二区| 成人福利在线看| 日韩一区二区三区免费观看| 亚洲欧美另类小说| 国产毛片精品国产一区二区三区| 欧美日韩一区三区四区| 国产欧美视频一区二区| 日韩经典中文字幕一区| 99国产麻豆精品| 久久久综合网站| 亚洲123区在线观看| thepron国产精品| 精品电影一区二区三区| 亚洲18女电影在线观看| 91色porny| 99久免费精品视频在线观看| 91麻豆精品91久久久久久清纯| √…a在线天堂一区| 国产一区在线观看麻豆| 制服视频三区第一页精品| 亚洲精品一二三| av一区二区不卡| 日本一区二区在线不卡| 免费成人深夜小野草| 欧美日韩精品综合在线| 一区二区三区四区五区视频在线观看| 国产91丝袜在线观看| 精品电影一区二区三区 | 亚洲国产成人在线| 青青草成人在线观看| 欧美日韩一区二区不卡| 一区二区三区精品久久久| 91在线小视频| 亚洲三级在线观看| av日韩在线网站| 国产精品午夜久久| 成人a区在线观看| 欧美激情一区三区| 风流少妇一区二区| 国产精品热久久久久夜色精品三区| 国产剧情一区二区三区| 久久久国产综合精品女国产盗摄| 精品一区二区免费视频| 精品成人佐山爱一区二区| 国产一区二区电影| 精品国产sm最大网站免费看| 精品一区二区三区的国产在线播放| 日韩欧美第一区| 狠狠色狠狠色综合| 国产拍揄自揄精品视频麻豆| 粉嫩aⅴ一区二区三区四区| 亚洲国产电影在线观看| 99国产精品久久久久久久久久久| 亚洲乱码日产精品bd| 色偷偷一区二区三区| 亚洲小少妇裸体bbw| 宅男噜噜噜66一区二区66| 久久国产精品99久久人人澡| 久久久久国色av免费看影院| 不卡的av中国片| 亚洲国产精品影院| 日韩视频一区二区在线观看| 国产乱对白刺激视频不卡| 日本一区二区视频在线观看| 色先锋久久av资源部| 婷婷综合在线观看| 精品久久一区二区三区| 高清免费成人av| 亚洲与欧洲av电影| 日韩视频永久免费| 成人免费视频一区| 亚洲综合视频在线| 精品理论电影在线| 99精品久久只有精品| 亚洲成人动漫一区| 久久中文字幕电影| 91视频一区二区| 秋霞午夜鲁丝一区二区老狼| 国产欧美日韩综合| 欧美日韩国产精品成人| 国产精品一级二级三级| 亚洲人成网站色在线观看| 欧美一区二区三区男人的天堂| 国产91精品一区二区麻豆网站| 亚洲精品国产品国语在线app| 日韩欧美色综合网站| 91偷拍与自偷拍精品| 日本特黄久久久高潮| 国产精品亲子伦对白| 91麻豆精品国产91| bt欧美亚洲午夜电影天堂| 亚洲bdsm女犯bdsm网站| 日本一区二区三区久久久久久久久不| 日本电影欧美片| 国产一区二区三区国产| 亚洲综合网站在线观看| 国产日韩av一区二区| 欧美日韩国产小视频在线观看| 国产传媒欧美日韩成人| 天堂va蜜桃一区二区三区漫画版| 国产精品丝袜黑色高跟| 制服丝袜日韩国产| 色婷婷综合在线| 福利视频网站一区二区三区| 免费人成精品欧美精品| 亚洲午夜在线视频| 国产精品成人免费精品自在线观看| 欧美xxx久久|