Skip to content

Commit

Permalink
* Introducing support for BGP Large Communities (1)
Browse files Browse the repository at this point in the history
  • Loading branch information
paololucente committed Oct 12, 2016
1 parent 93108f7 commit d1937d4
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 7 deletions.
9 changes: 5 additions & 4 deletions src/bgp/Makefile.am
Expand Up @@ -3,8 +3,9 @@ AM_CFLAGS = $(PMACCT_CFLAGS)
noinst_LTLIBRARIES = libbgp.la
libbgp_la_SOURCES = bgp.c bgp_aspath.c bgp_community.c \
bgp_ecommunity.c bgp_hash.c bgp_prefix.c bgp_table.c \
bgp_logdump.c bgp_util.c bgp_msg.c bgp_lookup.c bgp_aspath.h \
bgp_community.h bgp_ecommunity.h bgp.h bgp_hash.h \
bgp_logdump.h bgp_lookup.h bgp_msg.h bgp_packet.h \
bgp_prefix.h bgp_table.h bgp_util.h
bgp_logdump.c bgp_util.c bgp_msg.c bgp_lookup.c \
bgp_lcommunity.c bgp_aspath.h bgp_community.h \
bgp_ecommunity.h bgp.h bgp_hash.h bgp_logdump.h \
bgp_lookup.h bgp_msg.h bgp_packet.h bgp_prefix.h \
bgp_table.h bgp_util.h bgp_lcommunity.h
libbgp_la_CFLAGS = -I$(srcdir)/.. $(AM_CFLAGS)
3 changes: 3 additions & 0 deletions src/bgp/bgp.h
Expand Up @@ -61,6 +61,7 @@
#define BGP_ATTR_AS4_PATH 17
#define BGP_ATTR_AS4_AGGREGATOR 18
#define BGP_ATTR_AS_PATHLIMIT 21
#define BGP_ATTR_LARGE_COMMUNITIES 30 /* draft-ietf-idr-large-community-03 */

/* BGP Attribute flags. */
#define BGP_ATTR_FLAG_OPTIONAL 0x80 /* Attribute is optional. */
Expand Down Expand Up @@ -182,6 +183,7 @@ struct bgp_peer {
#include "bgp_aspath.h"
#include "bgp_community.h"
#include "bgp_ecommunity.h"
#include "bgp_lcommunity.h"
/* this include requires definition of bgp_peer */
#include "bgp_hash.h"

Expand All @@ -203,6 +205,7 @@ struct bgp_attr {
struct aspath *aspath;
struct community *community;
struct ecommunity *ecommunity;
struct lcommunity *lcommunity;
unsigned long refcnt;
u_int32_t flag;
struct in_addr nexthop;
Expand Down
28 changes: 28 additions & 0 deletions src/bgp/bgp_lcommunity.c
@@ -0,0 +1,28 @@
/*
pmacct (Promiscuous mode IP Accounting package)
pmacct is Copyright (C) 2003-2016 by Paolo Lucente
*/

/*
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/

#define __BGP_LCOMMUNITY_C

#include "pmacct.h"
#include "bgp_prefix.h"
#include "bgp.h"

/* XXX */
60 changes: 60 additions & 0 deletions src/bgp/bgp_lcommunity.h
@@ -0,0 +1,60 @@
/*
pmacct (Promiscuous mode IP Accounting package)
pmacct is Copyright (C) 2003-2016 by Paolo Lucente
*/

/*
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/

#ifndef _BGP_LCOMMUNITY_H_
#define _BGP_LCOMMUNITY_H_

#define LCOMMUNITY_SIZE 12

/* Large Communities attribute */
struct lcommunity
{
/* Reference counter */
unsigned long refcnt;

/* Size of Large Communities attribute. */
int size;

/* Large Communities value. */
u_int8_t *val;

/* Human readable format string. */
char *str;
};

/* Extended community value is eight octet. */
struct lcommunity_val
{
char val[LCOMMUNITY_SIZE];
};

#define lcom_length(X) ((X)->size * LCOMMUNITY_SIZE)

#if (!defined __BGP_LCOMMUNITY_C)
#define EXT extern
#else
#define EXT
#endif

/* XXX */

#undef EXT
#endif
13 changes: 13 additions & 0 deletions src/bgp/bgp_msg.c
Expand Up @@ -574,6 +574,9 @@ int bgp_attr_parse(struct bgp_peer *peer, struct bgp_attr *attr, char *ptr, int
case BGP_ATTR_EXT_COMMUNITIES:
ret = bgp_attr_parse_ecommunity(peer, attr_len, attr, ptr, flag);
break;
case BGP_ATTR_LARGE_COMMUNITIES:
ret = bgp_attr_parse_lcommunity(peer, attr_len, attr, ptr, flag);
break;
case BGP_ATTR_MULTI_EXIT_DISC:
ret = bgp_attr_parse_med(peer, attr_len, attr, ptr, flag);
break;
Expand Down Expand Up @@ -662,6 +665,16 @@ int bgp_attr_parse_ecommunity(struct bgp_peer *peer, u_int16_t len, struct bgp_a
return SUCCESS;
}

int bgp_attr_parse_lcommunity(struct bgp_peer *peer, u_int16_t len, struct bgp_attr *attr, char *ptr, u_int8_t flag)
{
/* XXX:
if (len == 0) attr->lcommunity = NULL;
else attr->lcommunity = (struct lcommunity *) lcommunity_parse(peer, ptr, len);
*/

return SUCCESS;
}

/* MED atrribute. */
int bgp_attr_parse_med(struct bgp_peer *peer, u_int16_t len, struct bgp_attr *attr, char *ptr, u_char flag)
{
Expand Down
1 change: 1 addition & 0 deletions src/bgp/bgp_msg.h
Expand Up @@ -37,6 +37,7 @@ EXT int bgp_write_open_msg(char *, char *, int, struct bgp_peer *);
EXT int bgp_attr_parse(struct bgp_peer *, struct bgp_attr *, char *, int, struct bgp_nlri *, struct bgp_nlri *);
EXT int bgp_attr_parse_community(struct bgp_peer *, u_int16_t, struct bgp_attr *, char *, u_int8_t);
EXT int bgp_attr_parse_ecommunity(struct bgp_peer *, u_int16_t, struct bgp_attr *, char *, u_int8_t);
EXT int bgp_attr_parse_lcommunity(struct bgp_peer *, u_int16_t, struct bgp_attr *, char *, u_int8_t);
EXT int bgp_attr_parse_aspath(struct bgp_peer *, u_int16_t, struct bgp_attr *, char *, u_int8_t);
EXT int bgp_attr_parse_as4path(struct bgp_peer *, u_int16_t, struct bgp_attr *, char *, u_int8_t, struct aspath **);
EXT int bgp_attr_parse_nexthop(struct bgp_peer *, u_int16_t, struct bgp_attr *, char *, u_int8_t);
Expand Down
2 changes: 1 addition & 1 deletion src/pmacct-build.h
@@ -1 +1 @@
#define PMACCT_BUILD "20161012-00"
#define PMACCT_BUILD "20161012-01"
2 changes: 0 additions & 2 deletions src/pretag.c
Expand Up @@ -595,7 +595,6 @@ void load_id_file(int acct_type, char *filename, struct id_table *t, struct plug
t->index_num = MAX_ID_TABLE_INDEXES;

#if defined ENABLE_IPV6
// XXX: for (ptr = t->ipv4_base, x = 0; x < MAX(t->ipv4_num, t->ipv6_num); ptr++, x++) {
for (ptr = t->ipv4_base, x = 0; x < (t->ipv4_num + t->ipv6_num); ptr++, x++) {
#else
for (ptr = t->ipv4_base, x = 0; x < t->ipv4_num; ptr++, x++) {
Expand All @@ -618,7 +617,6 @@ void load_id_file(int acct_type, char *filename, struct id_table *t, struct plug
pretag_index_allocate(t);

#if defined ENABLE_IPV6
// XXX: for (ptr = t->ipv4_base, x = 0; x < MAX(t->ipv4_num, t->ipv6_num); ptr++, x++) {
for (ptr = t->ipv4_base, x = 0; x < (t->ipv4_num + t->ipv6_num); ptr++, x++) {
#else
for (ptr = t->ipv4_base, x = 0; x < t->ipv4_num; ptr++, x++) {
Expand Down

0 comments on commit d1937d4

Please sign in to comment.