Author: adrian.chadd
Date: Sun Feb 22 21:27:13 2009
New Revision: 13844
Modified:
playpen/LUSCA_HEAD_bgp/libsqbgp/bgp_packet.c
playpen/LUSCA_HEAD_bgp/libsqbgp/bgp_rib.c
playpen/LUSCA_HEAD_bgp/libsqbgp/bgp_rib.h
Log:
In a very sick, twisted and ghetto fashion, store the origin AS in the
radix tree.
Modified: playpen/LUSCA_HEAD_bgp/libsqbgp/bgp_packet.c
==============================================================================
--- playpen/LUSCA_HEAD_bgp/libsqbgp/bgp_packet.c (original)
+++ playpen/LUSCA_HEAD_bgp/libsqbgp/bgp_packet.c Sun Feb 22 21:27:13 2009
@@ -408,7 +408,7 @@
bgp_rib_del_net(&bi->rn, us.withdraw[i], us.withdraw_mask[i]);
}
for (i = 0; i < us.nlri_cnt; i++) {
- bgp_rib_add_net(&bi->rn, us.nlri[i], us.nlri_mask[i]);
+ bgp_rib_add_net(&bi->rn, us.nlri[i], us.nlri_mask[i],
us.aspaths[us.aspath_len - 1]);
}
rc = 1;
Modified: playpen/LUSCA_HEAD_bgp/libsqbgp/bgp_rib.c
==============================================================================
--- playpen/LUSCA_HEAD_bgp/libsqbgp/bgp_rib.c (original)
+++ playpen/LUSCA_HEAD_bgp/libsqbgp/bgp_rib.c Sun Feb 22 21:27:13 2009
@@ -22,11 +22,25 @@
#include "bgp_rib.h"
#include "bgp_core.h"
+u_short
+bgp_rib_getasn(void *data)
+{
+ bgp_rib_aspath_t *a = data;
+ return a->origin_as;
+}
+
+static void
+bgp_rib_asn_free(radix_node_t *ptr, void *cbdata)
+{
+ free(ptr->data);
+}
+
int
bgp_rib_match_net(bgp_rib_head_t *head, struct in_addr addr, int masklen)
{
prefix_t * p;
radix_node_t *n;
+ bgp_rib_aspath_t *a;
p = New_Prefix(AF_INET, &addr, masklen, NULL);
@@ -34,11 +48,12 @@
if (n == NULL) {
debug(85, 1) ("bgp_rib_match_net: %s/%d: no match\n",
inet_ntoa(addr),
masklen);
Deref_Prefix(p);
- return 0;
+ return -1;
}
- debug(85, 1) ("bgp_rib_match_net: %s/%d: match\n", inet_ntoa(addr),
masklen);
+ debug(85, 1) ("bgp_rib_match_net: %s/%d: match; AS %d\n",
inet_ntoa(addr), masklen, bgp_rib_getasn(n->data));
Deref_Prefix(p);
- return 1;
+ a = n->data;
+ return a->origin_as;
}
/* initialize the radix tree structure */
@@ -54,21 +69,22 @@
void
bgp_rib_destroy(bgp_rib_head_t *head)
{
- Destroy_Radix(head->rh, NULL, NULL);
+ Destroy_Radix(head->rh, bgp_rib_asn_free, NULL);
}
void
bgp_rib_clean(bgp_rib_head_t *head)
{
- Clear_Radix(head->rh, NULL, NULL);
+ Clear_Radix(head->rh, bgp_rib_asn_free, NULL);
}
int
-bgp_rib_add_net(bgp_rib_head_t *head, struct in_addr addr, int masklen)
+bgp_rib_add_net(bgp_rib_head_t *head, struct in_addr addr, int masklen,
u_short origin_as)
{
prefix_t * p;
radix_node_t *n;
+ bgp_rib_aspath_t *a;
debug(85, 1) ("bgp_rib_add_net: %s/%d\n", inet_ntoa(addr), masklen);
p = New_Prefix(AF_INET, &addr, masklen, NULL);
@@ -83,6 +99,9 @@
/* XXX should verify? */
/* XXX should add some path data, etc? */
Deref_Prefix(p);
+ a = xcalloc(1, sizeof(bgp_rib_aspath_t));
+ a->origin_as = origin_as;
+ n->data = a;
return 1;
}
@@ -103,6 +122,7 @@
return 0;
}
/* XXX clear data associated with this prefix! */
+ bgp_rib_asn_free(n, NULL);
radix_remove(head->rh, n);
Deref_Prefix(p);
return 1;
Modified: playpen/LUSCA_HEAD_bgp/libsqbgp/bgp_rib.h
==============================================================================
--- playpen/LUSCA_HEAD_bgp/libsqbgp/bgp_rib.h (original)
+++ playpen/LUSCA_HEAD_bgp/libsqbgp/bgp_rib.h Sun Feb 22 21:27:13 2009
@@ -6,8 +6,13 @@
};
typedef struct _bgp_rib_head bgp_rib_head_t;
+struct _bgp_rib_aspath {
+ u_short origin_as;
+};
+typedef struct _bgp_rib_aspath bgp_rib_aspath_t;
+
extern int bgp_rib_match_net(bgp_rib_head_t *head, struct in_addr addr,
int masklen);
-extern int bgp_rib_add_net(bgp_rib_head_t *head, struct in_addr addr, int
masklen);
+extern int bgp_rib_add_net(bgp_rib_head_t *head, struct in_addr addr, int
masklen, u_short origin_as);
extern int bgp_rib_del_net(bgp_rib_head_t *head, struct in_addr addr, int
masklen);
extern void bgp_rib_init(bgp_rib_head_t *head);
extern void bgp_rib_destroy(bgp_rib_head_t *head);
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"lusca-commit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/lusca-commit?hl=en
-~----------~----~----~----~------~----~------~--~---