⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dn_neigh.c

📁 Linux内核源代码 为压缩文件 是<<Linux内核>>一书中的源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * DECnet       An implementation of the DECnet protocol suite for the LINUX *              operating system.  DECnet is implemented using the  BSD Socket *              interface as the means of communication with the user level. * *              DECnet Neighbour Functions (Adjacency Database and  *                                                        On-Ethernet Cache) * * Author:      Steve Whitehouse <SteveW@ACM.org> * * * Changes: *     Steve Whitehouse     : Fixed router listing routine *     Steve Whitehouse     : Added error_report functions *     Steve Whitehouse     : Added default router detection *     Steve Whitehouse     : Hop counts in outgoing messages *     Steve Whitehouse     : Fixed src/dst in outgoing messages so *                            forwarding now stands a good chance of *                            working. *     Steve Whitehouse     : Fixed neighbour states (for now anyway). * */#include <linux/config.h>#include <linux/net.h>#include <linux/socket.h>#include <linux/if_arp.h>#include <linux/if_ether.h>#include <linux/init.h>#include <linux/proc_fs.h>#include <linux/string.h>#include <linux/netfilter_decnet.h>#include <linux/spinlock.h>#include <asm/atomic.h>#include <net/neighbour.h>#include <net/dst.h>#include <net/dn.h>#include <net/dn_dev.h>#include <net/dn_neigh.h>#include <net/dn_route.h>static u32 dn_neigh_hash(const void *pkey, const struct net_device *dev);static int dn_neigh_construct(struct neighbour *);static void dn_long_error_report(struct neighbour *, struct sk_buff *);static void dn_short_error_report(struct neighbour *, struct sk_buff *);static int dn_long_output(struct sk_buff *);static int dn_short_output(struct sk_buff *);static int dn_phase3_output(struct sk_buff *);/* * For talking to broadcast devices: Ethernet & PPP */static struct neigh_ops dn_long_ops = {	AF_DECnet,	NULL,	NULL,	dn_long_error_report,	dn_long_output,	dn_long_output,	dev_queue_xmit,	dev_queue_xmit};/* * For talking to pointopoint and multidrop devices: DDCMP and X.25 */static struct neigh_ops dn_short_ops = {	AF_DECnet,	NULL,	NULL,	dn_short_error_report,	dn_short_output,	dn_short_output,	dev_queue_xmit,	dev_queue_xmit};/* * For talking to DECnet phase III nodes */static struct neigh_ops dn_phase3_ops = {	AF_DECnet,	NULL,	NULL,	dn_short_error_report, /* Can use short version here */	dn_phase3_output,	dn_phase3_output,	dev_queue_xmit,	dev_queue_xmit};struct neigh_table dn_neigh_table = {	NULL,	PF_DECnet,	sizeof(struct dn_neigh),	sizeof(dn_address),	dn_neigh_hash,	dn_neigh_construct,	NULL, /* pconstructor */	NULL, /* pdestructor */	NULL, /* proxyredo */	"dn_neigh_cache",	{ 		NULL,		NULL,		&dn_neigh_table,		0,		NULL,		NULL,		30 * HZ,	/* base_reachable_time */		1 * HZ,		/* retrans_time */		60 * HZ,	/* gc_staletime */		30 * HZ,	/* reachable_time */		5 * HZ,		/* delay_probe_time */		3,	/* queue_len */		0,	/* ucast_probes */		0,	/* app_probes */		0,	/* mcast_probes */		0,	/* anycast_delay */		0,	/* proxy_delay */		0,	/* proxy_qlen */		1 * HZ,	/* locktime */	},	30 * HZ,	/* gc_interval */	128,		/* gc_thresh1 */	512,		/* gc_thresh2 */	1024,		/* gc_thresh3 */	};static u32 dn_neigh_hash(const void *pkey, const struct net_device *dev){	u32 hash_val;	hash_val = *(dn_address *)pkey;	hash_val ^= (hash_val >> 10);	hash_val ^= (hash_val >> 3);	return hash_val & NEIGH_HASHMASK;}static int dn_neigh_construct(struct neighbour *neigh){	struct net_device *dev = neigh->dev;	struct dn_neigh *dn = (struct dn_neigh *)neigh;	struct dn_dev *dn_db = (struct dn_dev *)dev->dn_ptr;	if (dn_db == NULL)		return -EINVAL;	if (dn_db->neigh_parms)		neigh->parms = dn_db->neigh_parms;	if (dn_db->use_long)		neigh->ops = &dn_long_ops;	else		neigh->ops = &dn_short_ops;	if (dn->flags & DN_NDFLAG_P3)		neigh->ops = &dn_phase3_ops;	neigh->nud_state = NUD_NOARP;	neigh->output = neigh->ops->connected_output;	if ((dev->type == ARPHRD_IPGRE) || (dev->flags & IFF_POINTOPOINT))		memcpy(neigh->ha, dev->broadcast, dev->addr_len);	else if ((dev->type == ARPHRD_ETHER) || (dev->type == ARPHRD_LOOPBACK))		dn_dn2eth(neigh->ha, dn->addr);	else {		if (net_ratelimit())			printk(KERN_DEBUG "Trying to create neigh for hw %d\n",  dev->type);		return -EINVAL;	}	dn->blksize = 230;	return 0;}static void dn_long_error_report(struct neighbour *neigh, struct sk_buff *skb){	struct dn_skb_cb *cb = (struct dn_skb_cb *)skb->cb;	unsigned char *ptr;	printk(KERN_DEBUG "dn_long_error_report: called\n");	if (!(cb->rt_flags & DN_RT_F_RQR)) {		kfree_skb(skb);		return;	}	skb_push(skb, skb->data - skb->nh.raw);	ptr = skb->data;	*(unsigned short *)ptr = dn_htons(skb->len - 2);	ptr += 2;	if (*ptr & DN_RT_F_PF) {		char padlen = (*ptr & ~DN_RT_F_PF);		ptr += padlen;	}	*ptr++ |= (cb->rt_flags & ~DN_RT_F_RQR) | DN_RT_F_RTS;	ptr += 2;	dn_dn2eth(ptr, dn_ntohs(cb->src));	ptr += 8;	dn_dn2eth(ptr, dn_ntohs(cb->dst));	ptr += 6;	*ptr = 0;	skb->dst->neighbour->ops->queue_xmit(skb);}static void dn_short_error_report(struct neighbour *neigh, struct sk_buff *skb){	struct dn_skb_cb *cb = (struct dn_skb_cb *)skb->cb;	unsigned char *ptr;	printk(KERN_DEBUG "dn_short_error_report: called\n");	if (!(cb->rt_flags & DN_RT_F_RQR)) {		kfree_skb(skb);		return;	}	skb_push(skb, skb->data - skb->nh.raw);	ptr = skb->data;	*(unsigned short *)ptr = dn_htons(skb->len - 2);	ptr += 2;	*ptr++ = (cb->rt_flags & ~DN_RT_F_RQR) | DN_RT_F_RTS;	*(dn_address *)ptr = cb->src;	ptr += 2;	*(dn_address *)ptr = cb->dst;	ptr += 2;	*ptr = 0;	skb->dst->neighbour->ops->queue_xmit(skb);}static int dn_neigh_output_packet(struct sk_buff *skb){	struct dst_entry *dst = skb->dst;	struct neighbour *neigh = dst->neighbour;	struct net_device *dev = neigh->dev;	if (!dev->hard_header || dev->hard_header(skb, dev, ntohs(skb->protocol), neigh->ha, NULL, skb->len) >= 0)		return neigh->ops->queue_xmit(skb);	if (net_ratelimit())		printk(KERN_DEBUG "dn_neigh_output_packet: oops, can't send packet\n");	kfree_skb(skb);	return -EINVAL;}static int dn_long_output(struct sk_buff *skb){	struct dst_entry *dst = skb->dst;	struct neighbour *neigh = dst->neighbour;	struct net_device *dev = neigh->dev;	int headroom = dev->hard_header_len + sizeof(struct dn_long_packet) + 3;	unsigned char *data;	struct dn_long_packet *lp;	struct dn_skb_cb *cb = (struct dn_skb_cb *)skb->cb;	if (skb_headroom(skb) < headroom) {		struct sk_buff *skb2 = skb_realloc_headroom(skb, headroom);		if (skb2 == NULL) {			if (net_ratelimit())				printk(KERN_CRIT "dn_long_output: no memory\n");			kfree_skb(skb);			return -ENOBUFS;		}		kfree_skb(skb);		skb = skb2;		if (net_ratelimit())			printk(KERN_INFO "dn_long_output: Increasing headroom\n");	}	data = skb_push(skb, sizeof(struct dn_long_packet) + 3);	lp = (struct dn_long_packet *)(data+3);	*((unsigned short *)data) = dn_htons(skb->len - 2);	*(data + 2) = 1 | DN_RT_F_PF; /* Padding */	lp->msgflg   = DN_RT_PKT_LONG|(cb->rt_flags&(DN_RT_F_IE|DN_RT_F_RQR|DN_RT_F_RTS));	lp->d_area   = lp->d_subarea = 0;	dn_dn2eth(lp->d_id, dn_ntohs(cb->dst));	lp->s_area   = lp->s_subarea = 0;	dn_dn2eth(lp->s_id, dn_ntohs(cb->src));	lp->nl2      = 0;	lp->visit_ct = cb->hops & 0x3f;	lp->s_class  = 0;	lp->pt       = 0;	skb->nh.raw = skb->data;	return NF_HOOK(PF_DECnet, NF_DN_POST_ROUTING, skb, NULL, neigh->dev, dn_neigh_output_packet);}static int dn_short_output(struct sk_buff *skb){	struct dst_entry *dst = skb->dst;	struct neighbour *neigh = dst->neighbour;	struct net_device *dev = neigh->dev;	int headroom = dev->hard_header_len + sizeof(struct dn_short_packet) + 2;	struct dn_short_packet *sp;	unsigned char *data;	struct dn_skb_cb *cb = (struct dn_skb_cb *)skb->cb;        if (skb_headroom(skb) < headroom) {                struct sk_buff *skb2 = skb_realloc_headroom(skb, headroom);                if (skb2 == NULL) {			if (net_ratelimit())                        	printk(KERN_CRIT "dn_short_output: no memory\n");                        kfree_skb(skb);                        return -ENOBUFS;                }                kfree_skb(skb);                skb = skb2;		if (net_ratelimit())                	printk(KERN_INFO "dn_short_output: Increasing headroom\n");        }	data = skb_push(skb, sizeof(struct dn_short_packet) + 2);	*((unsigned short *)data) = dn_htons(skb->len - 2);	sp = (struct dn_short_packet *)(data+2);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -