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

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

?? iproute.c

?? 很好的TCP_IP協議源代碼分析,很適用很好
?? 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色综合久久天堂av综合| 久久精品亚洲麻豆av一区二区| 欧美va日韩va| 一区二区欧美国产| 国产91精品入口| 欧美成人精精品一区二区频| 亚洲永久精品国产| 91蜜桃网址入口| 国产欧美一区二区精品忘忧草| 日本中文字幕一区二区视频| 99久久精品国产一区二区三区 | 国内精品视频一区二区三区八戒| 在线欧美小视频| 日韩欧美一级在线播放| 91美女在线看| 亚洲国产高清不卡| 免费人成黄页网站在线一区二区| 精品污污网站免费看| 亚洲天堂精品在线观看| 成人午夜电影小说| 欧美激情一区二区三区蜜桃视频| 国产一区激情在线| 国产色产综合产在线视频| 国产精品无人区| 日韩av一区二区在线影视| 欧美日韩中字一区| 亚洲第一二三四区| 欧美四级电影在线观看| 亚洲午夜精品网| 欧美日韩一区二区三区在线看| 亚洲欧美日韩一区| 日本丶国产丶欧美色综合| 一区二区成人在线观看| 在线观看国产一区二区| 亚洲成a人片在线不卡一二三区| 一本一本久久a久久精品综合麻豆| 国产精品久久久久久福利一牛影视 | 久久久99精品免费观看| 国产精品小仙女| 国产精品每日更新| 日本丶国产丶欧美色综合| 午夜精品一区在线观看| 欧美一区二区三区在| 国产在线不卡视频| 自拍偷自拍亚洲精品播放| 色综合亚洲欧洲| 日韩影视精彩在线| 久久嫩草精品久久久久| 成人a级免费电影| 亚洲五月六月丁香激情| 日韩三级视频在线看| 高清beeg欧美| 午夜精品久久久久久久| 久久亚洲春色中文字幕久久久| 国产成人免费视频网站高清观看视频 | 成人视屏免费看| 亚洲午夜视频在线| 久久先锋影音av鲁色资源网| 波多野结衣精品在线| 午夜av一区二区三区| 久久亚洲一区二区三区明星换脸| www.一区二区| 久久精品99国产精品日本| 日本一区二区免费在线| 欧美午夜电影网| 国产一区二区久久| 亚洲电影你懂得| 国产婷婷色一区二区三区| 在线观看亚洲一区| 东方aⅴ免费观看久久av| 婷婷丁香久久五月婷婷| 国产精品美女一区二区在线观看| 在线观看91精品国产麻豆| 成人看片黄a免费看在线| 亚洲国产日韩在线一区模特| 国产日韩欧美制服另类| 欧美午夜免费电影| aaa欧美大片| 国产美女久久久久| 日韩电影在线免费看| |精品福利一区二区三区| 26uuu久久天堂性欧美| 欧美日韩aaaaa| 不卡影院免费观看| 国产露脸91国语对白| 日韩在线一区二区三区| 一区二区三区国产精品| 国产精品国产三级国产| 久久久蜜臀国产一区二区| 欧美日韩精品欧美日韩精品一| 99久久777色| 成人一区二区三区在线观看 | 亚洲3atv精品一区二区三区| 欧美韩日一区二区三区| 337p粉嫩大胆噜噜噜噜噜91av | 99久久久国产精品免费蜜臀| 久久精品国产亚洲高清剧情介绍| 亚洲国产精品一区二区尤物区| 国产女主播在线一区二区| 欧美一级日韩一级| 欧美揉bbbbb揉bbbbb| 一本久久综合亚洲鲁鲁五月天| 成人丝袜高跟foot| 国产91对白在线观看九色| 国产一区二区在线观看视频| 久久99久久99精品免视看婷婷 | 一区二区国产盗摄色噜噜| 国产精品国产馆在线真实露脸| 久久久精品综合| 国产天堂亚洲国产碰碰| 亚洲国产精品成人久久综合一区| 久久久www成人免费毛片麻豆| 久久久久久久网| 国产女人18水真多18精品一级做 | 99精品欧美一区二区三区小说| 成人免费看视频| 91美女福利视频| 色婷婷亚洲精品| 欧美精品日韩一区| 日韩欧美国产一区二区在线播放| 欧美va亚洲va香蕉在线| 久久免费国产精品 | 国产喷白浆一区二区三区| 日本一区免费视频| 亚洲欧美日韩中文播放 | 成人三级伦理片| 99r国产精品| 欧美日韩国产一级片| 91精品国产免费| 国产亚洲欧洲997久久综合| 国产精品伦理一区二区| 亚洲一区在线观看视频| 日本不卡123| 成人午夜电影久久影院| 日本精品一区二区三区高清| 欧美精品vⅰdeose4hd| 2023国产精品自拍| 成人欧美一区二区三区黑人麻豆| 亚洲自拍偷拍欧美| 精品亚洲国产成人av制服丝袜| 成人丝袜18视频在线观看| 91黄色激情网站| 欧美成人一区二区三区| ...中文天堂在线一区| 日韩高清在线不卡| 成人激情动漫在线观看| 欧美精品丝袜久久久中文字幕| 国产午夜精品久久久久久久 | 激情av综合网| 在线观看精品一区| 久久久夜色精品亚洲| 亚洲国产日日夜夜| 床上的激情91.| 欧美一区二区三级| 亚洲乱码国产乱码精品精可以看| 美女免费视频一区| 色综合一区二区| 久久精品一区二区三区不卡 | voyeur盗摄精品| 日韩你懂的电影在线观看| 亚洲精品乱码久久久久| 国产剧情一区在线| 欧美一区二区视频在线观看2020 | 欧美成人性战久久| 亚洲一区二区三区四区中文字幕| 国产一区91精品张津瑜| 在线观看网站黄不卡| 国产精品美女久久久久久久久久久 | 国产三级一区二区| 日韩电影在线看| 欧美在线免费观看亚洲| 国产精品第四页| 国产精品一区二区在线观看网站| 777a∨成人精品桃花网| 亚洲自拍偷拍麻豆| 一本到一区二区三区| 亚洲国产精品传媒在线观看| 久久99国内精品| 日韩精品一区国产麻豆| 午夜精品久久久久久久久久久| 99国产麻豆精品| 国产精品久久久久一区二区三区| 国产在线播精品第三| 日韩欧美一级二级三级久久久| 亚洲线精品一区二区三区八戒| 91一区二区在线观看| 中文字幕一区二区三区在线观看| 国产剧情一区在线| 国产欧美一区视频| 成人永久免费视频| 欧美激情艳妇裸体舞| 国产福利一区二区三区视频在线 | 成人av中文字幕| 国产精品视频一区二区三区不卡| 国产精品一区二区久久不卡| 国产日产欧美一区二区三区| 国产自产v一区二区三区c| 久久日韩粉嫩一区二区三区| 国产精品影视在线| 日本一区二区三区四区在线视频|