Skip to content

Commit

Permalink
Fixed setup forwarding and vrr_should_add to prevent setup loops.
Browse files Browse the repository at this point in the history
  • Loading branch information
tadfisher committed Aug 12, 2010
1 parent a284c29 commit 7ec0de3
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 30 deletions.
15 changes: 13 additions & 2 deletions vrr_data.c
Original file line number Diff line number Diff line change
Expand Up @@ -662,10 +662,21 @@ int vset_should_add(u32 node)
int i = 0;
unsigned long flags;

if (vset_size < VRR_VSET_SIZE)
spin_lock_irqsave(&vrr_vset_lock, flags);

list_for_each(pos, &vset.list) {
tmp = list_entry(pos, vset_list_t, list);
if (tmp->node == node) {
spin_unlock_irqrestore(&vrr_vset_lock, flags);
return 0;
}
}

if (vset_size < VRR_VSET_SIZE) {
spin_unlock_irqrestore(&vrr_vset_lock, flags);
return 1;
}

spin_lock_irqsave(&vrr_vset_lock, flags);
list_for_each(pos, &vset.list) {
tmp = list_entry(pos, vset_list_t, list);
left[i] = tmp->diff_left;
Expand Down
35 changes: 16 additions & 19 deletions vrr_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,6 @@ static int vrr_rcv_setup_req(struct sk_buff *skb, const struct vrr_header *vh)
skb_copy_bits(skb, offset, &proxy, step);
proxy = ntohl(proxy);
offset += step;
VRR_DBG("Proxy: %x", proxy);

skb_copy_bits(skb, offset, &vset_size, step);
vset_size = ntohl(vset_size);
Expand Down Expand Up @@ -356,33 +355,32 @@ static int vrr_rcv_setup(struct sk_buff *skb, const struct vrr_header *vh)
src = ntohl(vh->src_id);
dst = ntohl(vh->dest_id);

skb_copy_bits(skb, offset, &pid, step);
pid = ntohl(pid);
offset += step;

skb_copy_bits(skb, offset, &proxy, step);
proxy = ntohl(proxy);
offset += step;

skb_copy_bits(skb, offset, &pid, step);
pid = ntohl(pid);
offset += step;
VRR_DBG("src:%x dst:%x proxy:%x pid:%x", src, dst, proxy, pid);

eth_header_parse(skb, src_addr);

if (!memcmp(skb->dev->dev_addr, src_addr, ETH_ALEN)) {
VRR_DBG("Received setup from myself");
sender = get_vrr_id();
} else {
in_pset = pset_lookup_mac(src_addr, &sender);
if (!in_pset) {
/* TearDownPath(<pid, src>, null) */
VRR_DBG("Sender is not in pset!");
return 0;
}
}
in_pset = pset_lookup_mac(src_addr, &sender);
if (!in_pset) {
/* TearDownPath(<pid, src>, null) */
VRR_DBG("Sender is not in pset!");
return 0;
}

if (pset_get_status(dst) == PSET_UNKNOWN)
nh = rt_get_next(proxy);
nh = (dst == me->id) ? 0 : rt_get_next(proxy);
else
nh = dst;

VRR_DBG("nh: %x", nh);

if (!rt_add_route(src, dst, sender, nh, pid)) {
/* TearDownPath(<pid, src>, null) */
VRR_DBG("Couldn't add route. Should tear down path to %x", src);
Expand Down Expand Up @@ -416,7 +414,8 @@ static int vrr_rcv_setup(struct sk_buff *skb, const struct vrr_header *vh)
return 0;
}

if (dst == get_vrr_id() && vrr_add(src, vset_size, vset)) {
if (vrr_add(src, vset_size, vset)) {
VRR_DBG("Yay! Received multi-hop setup message from %x!", src);
me->active = 1;
return 0;
} else {
Expand Down Expand Up @@ -550,8 +549,6 @@ int vrr_local_rcv_setup(u32 dst, u32 pid, u32 proxy,
u32 src = get_vrr_id();
u32 nh;

VRR_DBG("Receiving setup message from myself.");

if (pset_get_status(dst) == PSET_UNKNOWN)
nh = rt_get_next(proxy);
else
Expand Down
41 changes: 32 additions & 9 deletions vrr_output.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ int vrr_output(struct sk_buff *skb, struct vrr_node *vrr,

vh = (struct vrr_header *)skb->data;

VRR_INFO("vrr_version: %x", vh->vrr_version);
VRR_INFO("pkt_type: %x", vh->pkt_type);
VRR_INFO("protocol: %x", ntohs(vh->protocol));
VRR_INFO("data_len: %x", ntohs(vh->data_len));
VRR_INFO("free: %x", vh->free);
VRR_INFO("h_csum: %x", vh->h_csum);
VRR_INFO("src_id: %x", ntohl(vh->src_id));
VRR_INFO("dest_id: %x", ntohl(vh->dest_id));

list_for_each(pos, &vrr->dev_list.list) {
tmp = list_entry(pos, struct vrr_interface_list, list);
dev = dev_get_by_name(&init_net, tmp->dev_name);
Expand All @@ -26,13 +35,13 @@ int vrr_output(struct sk_buff *skb, struct vrr_node *vrr,
if (clone) {
skb_reset_network_header(clone);
clone->dev = dev;
VRR_DBG("dev->dev_addr: %x:%x:%x:%x:%x:%x",
dev->dev_addr[0],
dev->dev_addr[1],
dev->dev_addr[2],
dev->dev_addr[3],
dev->dev_addr[4],
dev->dev_addr[5]);
VRR_DBG("vh->dest_mac: %x:%x:%x:%x:%x:%x",
vh->dest_mac[0],
vh->dest_mac[1],
vh->dest_mac[2],
vh->dest_mac[3],
vh->dest_mac[4],
vh->dest_mac[5]);
dev_hard_header(clone, dev, ETH_P_VRR, vh->dest_mac,
dev->dev_addr, clone->len);
VRR_DBG("Sending over iface %s", tmp->dev_name);
Expand Down Expand Up @@ -84,10 +93,24 @@ int vrr_forward_setup_req(struct sk_buff *skb,
return 0;
}

skb_pull(skb, sizeof(struct ethhdr));

myvh = (struct vrr_header *)skb_network_header(skb);

VRR_DBG("vh->dest_mac: %x:%x:%x:%x:%x:%x",
vh->dest_mac[0],
vh->dest_mac[1],
vh->dest_mac[2],
vh->dest_mac[3],
vh->dest_mac[4],
vh->dest_mac[5]);

memcpy(myvh->dest_mac, dest_mac, ETH_ALEN);
VRR_DBG("vh->dest_mac: %x:%x:%x:%x:%x:%x",
vh->dest_mac[0],
vh->dest_mac[1],
vh->dest_mac[2],
vh->dest_mac[3],
vh->dest_mac[4],
vh->dest_mac[5]);

return vrr_output(skb, vrr_get_node(), VRR_SETUP_REQ);
}

0 comments on commit 7ec0de3

Please sign in to comment.