patch-2.3.15 linux/net/decnet/dn_neigh.c
Next file: linux/net/decnet/dn_nsp_in.c
Previous file: linux/net/decnet/dn_fib.c
Back to the patch index
Back to the overall index
- Lines: 328
- Date:
Mon Aug 23 10:01:02 1999
- Orig file:
v2.3.14/linux/net/decnet/dn_neigh.c
- Orig date:
Wed Aug 18 11:38:49 1999
diff -u --recursive --new-file v2.3.14/linux/net/decnet/dn_neigh.c linux/net/decnet/dn_neigh.c
@@ -29,6 +29,7 @@
#include <linux/init.h>
#include <linux/proc_fs.h>
#include <linux/string.h>
+#include <linux/netfilter_decnet.h>
#include <asm/atomic.h>
#include <asm/spinlock.h>
#include <net/neighbour.h>
@@ -38,6 +39,7 @@
#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 *);
@@ -92,11 +94,13 @@
NULL,
PF_DECnet,
sizeof(struct dn_neigh),
- ETH_ALEN,
+ sizeof(dn_address),
+ dn_neigh_hash,
dn_neigh_construct,
NULL, /* pconstructor */
NULL, /* pdestructor */
NULL, /* proxyredo */
+ "dn_neigh_cache",
{
NULL,
NULL,
@@ -125,6 +129,17 @@
};
+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;
@@ -148,6 +163,16 @@
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;
@@ -217,13 +242,27 @@
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;
- struct dn_dev *dn_db = dev->dn_ptr;
int headroom = dev->hard_header_len + sizeof(struct dn_long_packet) + 3;
unsigned char *data;
struct dn_long_packet *lp;
@@ -252,9 +291,9 @@
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, cb->dst);
+ dn_dn2eth(lp->d_id, dn_ntohs(cb->dst));
lp->s_area = lp->s_subarea = 0;
- dn_dn2eth(lp->s_id, cb->src);
+ dn_dn2eth(lp->s_id, dn_ntohs(cb->src));
lp->nl2 = 0;
lp->visit_ct = cb->hops & 0x3f;
lp->s_class = 0;
@@ -262,15 +301,7 @@
skb->nh.raw = skb->data;
- if (dev->hard_header(skb, dev, ntohs(skb->protocol), neigh->ha,
- dn_db->addr, skb->len) >= 0)
- return neigh->ops->queue_xmit(skb);
-
- if (net_ratelimit())
- printk(KERN_DEBUG "dn_long_output: oops, can't sent packet\n");
-
- kfree_skb(skb);
- return -EINVAL;
+ 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)
@@ -309,12 +340,7 @@
skb->nh.raw = skb->data;
- if (dev->hard_header(skb, dev, ntohs(skb->protocol), neigh->ha,
- NULL, skb->len) >= 0)
- return neigh->ops->queue_xmit(skb);
-
- kfree_skb(skb);
- return -EINVAL;
+ return NF_HOOK(PF_DECnet, NF_DN_POST_ROUTING, skb, NULL, neigh->dev, dn_neigh_output_packet);
}
/*
@@ -350,18 +376,13 @@
sp = (struct dn_short_packet *)(data + 2);
sp->msgflg = DN_RT_PKT_SHORT|(cb->rt_flags&(DN_RT_F_RQR|DN_RT_F_RTS));
- sp->dstnode = cb->dst & __constant_htons(0x03ff);
- sp->srcnode = cb->src & __constant_htons(0x03ff);
+ sp->dstnode = cb->dst & dn_htons(0x03ff);
+ sp->srcnode = cb->src & dn_htons(0x03ff);
sp->forward = cb->hops & 0x3f;
skb->nh.raw = skb->data;
- if (dev->hard_header(skb, dev, ntohs(skb->protocol), neigh->ha,
- NULL, skb->len) >= 0)
- return neigh->ops->queue_xmit(skb);
-
- kfree_skb(skb);
- return -EINVAL;
+ return NF_HOOK(PF_DECnet, NF_DN_POST_ROUTING, skb, NULL, neigh->dev, dn_neigh_output_packet);
}
/*
@@ -372,20 +393,20 @@
*/
struct neighbour *dn_neigh_lookup(struct neigh_table *tbl, void *ptr)
{
- int i;
struct neighbour *neigh;
+ u32 hash_val;
- start_bh_atomic();
- for(i = 0; i < NEIGH_HASHMASK; i++) {
- for(neigh = tbl->hash_buckets[i]; neigh != NULL; neigh = neigh->next) {
- if (memcmp(neigh->primary_key, ptr, ETH_ALEN) == 0) {
- atomic_inc(&neigh->refcnt);
- end_bh_atomic();
- return neigh;
- }
+ hash_val = tbl->hash(ptr, NULL);
+
+ read_lock_bh(&tbl->lock);
+ for(neigh = tbl->hash_buckets[hash_val]; neigh != NULL; neigh = neigh->next) {
+ if (memcmp(neigh->primary_key, ptr, tbl->key_len) == 0) {
+ atomic_inc(&neigh->refcnt);
+ read_unlock_bh(&tbl->lock);
+ return neigh;
}
}
- end_bh_atomic();
+ read_unlock_bh(&tbl->lock);
return NULL;
}
@@ -418,30 +439,39 @@
struct neighbour *neigh;
struct dn_neigh *dn;
struct dn_dev *dn_db;
+ dn_address src;
+
+ src = dn_eth2dn(msg->id);
- start_bh_atomic();
- neigh = __neigh_lookup(&dn_neigh_table, msg->id, skb->dev, 1);
- end_bh_atomic();
+ neigh = __neigh_lookup(&dn_neigh_table, &src, skb->dev, 1);
dn = (struct dn_neigh *)neigh;
if (neigh) {
- neigh_update(neigh, msg->id, NUD_NOARP, 1, 0);
- neigh->used = jiffies;
+ write_lock(&neigh->lock);
+ neigh->used = jiffies;
dn_db = (struct dn_dev *)neigh->dev->dn_ptr;
- dn->blksize = dn_ntohs(msg->blksize);
- dn->priority = msg->priority;
+ if (!(neigh->nud_state & NUD_PERMANENT)) {
+ neigh->updated = jiffies;
+
+ if (neigh->dev->type == ARPHRD_ETHER)
+ memcpy(neigh->ha, &skb->mac.ethernet->h_source, ETH_ALEN);
- dn->flags &= ~DN_NDFLAG_P3;
+ dn->blksize = dn_ntohs(msg->blksize);
+ dn->priority = msg->priority;
- switch(msg->iinfo & DN_RT_INFO_TYPE) {
- case DN_RT_INFO_L1RT:
- dn->flags &=~DN_NDFLAG_R2;
- dn->flags |= DN_NDFLAG_R1;
- case DN_RT_INFO_L2RT:
- dn->flags |= DN_NDFLAG_R2;
+ dn->flags &= ~DN_NDFLAG_P3;
+
+ switch(msg->iinfo & DN_RT_INFO_TYPE) {
+ case DN_RT_INFO_L1RT:
+ dn->flags &=~DN_NDFLAG_R2;
+ dn->flags |= DN_NDFLAG_R1;
+ break;
+ case DN_RT_INFO_L2RT:
+ dn->flags |= DN_NDFLAG_R2;
+ }
}
if (!dn_db->router) {
@@ -450,7 +480,7 @@
if (msg->priority > ((struct dn_neigh *)dn_db->router)->priority)
neigh_release(xchg(&dn_db->router, neigh_clone(neigh)));
}
-
+ write_unlock(&neigh->lock);
neigh_release(neigh);
}
@@ -465,21 +495,30 @@
struct endnode_hello_message *msg = (struct endnode_hello_message *)skb->data;
struct neighbour *neigh;
struct dn_neigh *dn;
+ dn_address src;
+
+ src = dn_eth2dn(msg->id);
- start_bh_atomic();
- neigh = __neigh_lookup(&dn_neigh_table, msg->id, skb->dev, 1);
- end_bh_atomic();
+ neigh = __neigh_lookup(&dn_neigh_table, &src, skb->dev, 1);
dn = (struct dn_neigh *)neigh;
if (neigh) {
- neigh_update(neigh, msg->id, NUD_NOARP, 1, 0);
+ write_lock(&neigh->lock);
+
neigh->used = jiffies;
- dn->flags &= ~(DN_NDFLAG_R1 | DN_NDFLAG_R2);
- dn->blksize = dn_ntohs(msg->blksize);
- dn->priority = 0;
+ if (!(neigh->nud_state & NUD_PERMANENT)) {
+ neigh->updated = jiffies;
+
+ if (neigh->dev->type == ARPHRD_ETHER)
+ memcpy(neigh->ha, &skb->mac.ethernet->h_source, ETH_ALEN);
+ dn->flags &= ~(DN_NDFLAG_R1 | DN_NDFLAG_R2);
+ dn->blksize = dn_ntohs(msg->blksize);
+ dn->priority = 0;
+ }
+ write_unlock(&neigh->lock);
neigh_release(neigh);
}
@@ -516,7 +555,7 @@
struct neigh_table *tbl = &dn_neigh_table;
unsigned char *rs = ptr;
- start_bh_atomic();
+ read_lock_bh(&tbl->lock);
for(i = 0; i < NEIGH_HASHMASK; i++) {
for(neigh = tbl->hash_buckets[i]; neigh != NULL; neigh = neigh->next) {
@@ -533,7 +572,7 @@
t++;
if (rs == NULL)
continue;
- memcpy(rs, dn->addr, ETH_ALEN);
+ dn_dn2eth(rs, dn->addr);
rs += 6;
*rs = neigh->nud_state & NUD_CONNECTED ? 0x80 : 0x0;
*rs |= dn->priority;
@@ -541,7 +580,7 @@
}
}
- end_bh_atomic();
+ read_unlock_bh(&tbl->lock);
return t;
}
@@ -569,7 +608,7 @@
read_lock(&n->lock);
len += sprintf(buffer+len, "%-7s %s%s%s %02x %02d %07ld %-8s\n",
- dn_addr2asc(dn_ntohs(dn_eth2dn(dn->addr)), buf),
+ dn_addr2asc(dn_ntohs(dn->addr), buf),
(dn->flags&DN_NDFLAG_R1) ? "1" : "-",
(dn->flags&DN_NDFLAG_R2) ? "2" : "-",
(dn->flags&DN_NDFLAG_P3) ? "3" : "-",
FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)