Skip to content

Commit

Permalink
* sFlow probe: BGP daemon thread tied up with sfprobe plugin to
Browse files Browse the repository at this point in the history
  dynamically update src_as and dst_as primitives (only) as BGP
  messages come in.
  • Loading branch information
paololucente authored and paolo committed Sep 3, 2009
1 parent 3f94099 commit 2a346e6
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 8 deletions.
53 changes: 47 additions & 6 deletions src/pkt_handlers.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,16 @@ void evaluate_packet_handlers()
if (channels_list[index].aggregation & (COUNT_STD_COMM|COUNT_EXT_COMM|COUNT_LOCAL_PREF|COUNT_MED|
COUNT_AS_PATH|COUNT_PEER_SRC_IP|COUNT_PEER_DST_IP|COUNT_PEER_DST_AS)
|| (channels_list[index].aggregation & (COUNT_SRC_AS|COUNT_DST_AS) && config.nfacctd_as == NF_AS_BGP)) {
if (config.acct_type == ACCT_PM && config.nfacctd_bgp) {
channels_list[index].phandler[primitives] = bgp_ext_handler;
if (config.acct_type != ACCT_PM && channels_list[index].plugin->type.id == PLUGIN_ID_SFPROBE) {
/* Let's basically get out of here this case - XXX: silently */
}
else if (config.acct_type == ACCT_PM && config.nfacctd_bgp) {
if (channels_list[index].plugin->type.id == PLUGIN_ID_SFPROBE) {
channels_list[index].phandler[primitives] = sfprobe_bgp_ext_handler;
}
else {
channels_list[index].phandler[primitives] = bgp_ext_handler;
}
primitives++;
}
else if (config.acct_type == ACCT_NF && config.nfacctd_bgp) {
Expand Down Expand Up @@ -444,10 +452,12 @@ void sfprobe_payload_handler(struct channels_list_entry *chptr, struct packet_pt
char *buf = (char *) *data, *tmpp = (char *) &tmp;
int space = (chptr->bufend - chptr->bufptr) - PpayloadSz;

src_host_handler(chptr, pptrs, &tmpp);
dst_host_handler(chptr, pptrs, &tmpp);
memcpy(&payload->src_ip, &tmp.primitives.src_ip, HostAddrSz);
memcpy(&payload->dst_ip, &tmp.primitives.dst_ip, HostAddrSz);
if (chptr->plugin->cfg.networks_file) {
src_host_handler(chptr, pptrs, &tmpp);
dst_host_handler(chptr, pptrs, &tmpp);
memcpy(&payload->src_ip, &tmp.primitives.src_ip, HostAddrSz);
memcpy(&payload->dst_ip, &tmp.primitives.dst_ip, HostAddrSz);
}

payload->cap_len = ((struct pcap_pkthdr *)pptrs->pkthdr)->caplen;
payload->pkt_len = ((struct pcap_pkthdr *)pptrs->pkthdr)->len;
Expand Down Expand Up @@ -1496,6 +1506,37 @@ void bgp_ext_handler(struct channels_list_entry *chptr, struct packet_ptrs *pptr
}
}

void sfprobe_bgp_ext_handler(struct channels_list_entry *chptr, struct packet_ptrs *pptrs, char **data)
{
struct pkt_payload *payload = (struct pkt_payload *) *data;
struct bgp_node *src_ret = (struct bgp_node *) pptrs->bgp_src;
struct bgp_node *dst_ret = (struct bgp_node *) pptrs->bgp_dst;
struct bgp_peer *peer = (struct bgp_peer *) pptrs->bgp_peer;
struct bgp_info *info;

if (src_ret) {
info = (struct bgp_info *) src_ret->info;
if (info && info->attr) {
if (config.nfacctd_as == NF_AS_BGP) {
if (chptr->aggregation & COUNT_SRC_AS && info->attr->aspath) {
payload->src_ip.address.ipv4.s_addr = evaluate_last_asn(info->attr->aspath);
}
}
}
}

if (dst_ret) {
info = (struct bgp_info *) dst_ret->info;
if (info && info->attr) {
if (config.nfacctd_as == NF_AS_BGP) {
if (chptr->aggregation & COUNT_DST_AS && info->attr->aspath) {
payload->dst_ip.address.ipv4.s_addr = evaluate_last_asn(info->attr->aspath);
}
}
}
}
}

void NF_bgp_peer_src_as_fromstd_handler(struct channels_list_entry *chptr, struct packet_ptrs *pptrs, char **data)
{
struct pkt_data *pdata = (struct pkt_data *) *data;
Expand Down
1 change: 1 addition & 0 deletions src/pkt_handlers.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ EXT void NF_bgp_peer_src_as_fromext_handler(struct channels_list_entry *, struct
EXT void NF_bgp_peer_src_as_fromstd_handler(struct channels_list_entry *, struct packet_ptrs *, char **);

EXT void bgp_ext_handler(struct channels_list_entry *, struct packet_ptrs *, char **);
EXT void sfprobe_bgp_ext_handler(struct channels_list_entry *, struct packet_ptrs *, char **);
EXT void bgp_peer_src_as_frommap_handler(struct channels_list_entry *, struct packet_ptrs *, char **);

EXT void SF_src_mac_handler(struct channels_list_entry *, struct packet_ptrs *, char **);
Expand Down
4 changes: 2 additions & 2 deletions src/sfprobe_plugin/sfprobe_plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ static void init_agent(SflSp *sp)
sp->sampler = sfl_agent_getSampler(sp->agent, &dsi);
}


#define NF_AS_BGP 2
/*_________________---------------------------__________________
_________________ readPacket __________________
-----------------___________________________------------------
Expand Down Expand Up @@ -360,7 +360,7 @@ static void readPacket(SflSp *sp, struct pkt_payload *hdr, const unsigned char *
informations; we will fill in only infos pertaining
to src and dst ASNs
*/
if (config.networks_file) {
if (config.networks_file || config.nfacctd_as == NF_AS_BGP) {
memset(&gatewayHdrElem, 0, sizeof(gatewayHdrElem));
memset(&as_path_segment, 0, sizeof(as_path_segment));
gatewayHdrElem.tag = SFLFLOW_EX_GATEWAY;
Expand Down

0 comments on commit 2a346e6

Please sign in to comment.