Skip to content

Commit

Permalink
Merge pull request #10 from spale75/dev
Browse files Browse the repository at this point in the history
release v1.1.3
  • Loading branch information
spale75 authored Nov 1, 2017
2 parents 3f6764e + 1aede9a commit 3fcbd36
Show file tree
Hide file tree
Showing 12 changed files with 218 additions and 85 deletions.
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ Piranha has one configuration file located in <destination folder>/etc/pir

# Export options: Choose which route attributes will be exported to the dump files
export origin # IGP/EGP/Unknown
export nexthop # NEXT_HOP
export aspath # AS_PATH
export community # COMMUNITY
export extcommunity # EXTENDED COMMUNITY
Expand Down Expand Up @@ -162,7 +163,7 @@ Piranha has one configuration file located in <destination folder>/etc/pir

### Start/Stop/Restart

<install dir>/etc/piranhactl <start|restart|stop>
<install dir>/bin/piranhactl <start|restart|stop>

### Status (state of all neighbors)

Expand All @@ -187,21 +188,21 @@ With the tool *&lt;install dir&gt;/bin/ptoa* data from the dump files can be exp

#### Human readable format

2017-10-21 21:31:54 peer ip 2a03:2260::5 AS 201701
2017-10-21 21:31:54 peer ip 2a03:2260::5 AS 201701 TYPE eBGP
2017-10-21 21:31:54 prefix announce 2a06:dac0::/29 origin IGP aspath 201701 13030 25180 202939 community 5093:5349 6629:6885 7141:7397
2017-10-21 21:31:55 eof

#### Machine readable format

1508621514|P|2a03:2260::5|201701
1508621514|P|2a03:2260::5|201701|eBGP
1508621514|A|2a06:dac0::|29|O|I|AP|201701 13030 25180 202939|C|5093:5349 5605:5861 6629:6885 7141:7397
1508621515|E

#### JSON format
When decoding JSON, you must decode each line individually. Because dump file can have millions of routes, it would use too much resouces for the decoder to decode them at once. This is why there is one JSON object per line.

{ "timestamp": 1508621514, "type": "peer", "msg": { "peer": { "proto": "ipv6", "ip": "2a03:2260::5", "asn": 201701 } } }
{ "timestamp": 1508621514, "type": "announce", "msg": { "prefix": "2a06:dac0::/29", "origin": "IGP", "aspath": [ 201701, 13030, 25180, 202939 ], "community": [ "5093:5349", "5605:5861", "6629:6885", "7141:7397" ] } }
{ "timestamp": 1508621514, "type": "peer", "msg": { "peer": { "proto": "ipv6", "ip": "2a03:2260::5", "asn": 201701, "type": "eBGP" } } }
{ "timestamp": 1508621514, "type": "announce", "msg": { "prefix": "2a06:dac0::/29", "origin": "IGP", "nexthop": "2a06:ffff::1", "aspath": [ 201701, 13030, 25180, 202939 ], "community": [ "5093:5349", "5605:5861", "6629:6885", "7141:7397" ] } }
{ "timestamp": 1508621515, "type": "footer" }

### Message type tags in DUMPs
Expand All @@ -210,7 +211,7 @@ Colons can be used to align columns.
| Human | Machine | JSON | Description |
|:----------|:--------|:----------|:---------------------------------------------------------------------------------------------------------------|
| peer | P | peer | First message in any dump describing the neighbor |
| announce | A | announce | BGP prefix announce, optional origin (O), aspath (AP), community (C) and extended community (EC) subcomponents |
| announce | A | announce | BGP prefix announce, optional origin (O), nexthop (NH), aspath (AP), community (C) and extended community (EC) subcomponents |
| withdrawn | W | withdrawn | BGP prefix withdrawn |
| eof | E | footer | Last message in any dump, has no other value |

Expand Down
12 changes: 11 additions & 1 deletion inc/p_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,15 @@
#define BGP_ORIGIN_EGP 1
#define BGP_ORIGIN_UNKN 2

#define BGP_TYPE_IBGP 0
#define BGP_TYPE_EBGP 1

#define EXPORT_ORIGIN 0x01
#define EXPORT_ASPATH 0x02
#define EXPORT_COMMUNITY 0x04
#define EXPORT_EXTCOMMUNITY 0x08
#define EXPORT_LARGECOMMUNITY 0x10
#define EXPORT_NEXT_HOP 0x20

#define DUMP_OPEN 10
#define DUMP_CLOSE 11
Expand Down Expand Up @@ -188,6 +192,7 @@ struct dump_msg
uint8_t type;
uint16_t len;
uint64_t ts;
uint64_t uts;
#ifdef CC_GCC
} __attribute__((packed));
#else
Expand All @@ -198,6 +203,7 @@ struct dump_header4
{
uint32_t ip;
uint32_t as;
uint8_t type;
#ifdef CC_GCC
} __attribute__((packed));
#else
Expand All @@ -206,8 +212,9 @@ struct dump_header4

struct dump_header6
{
uint8_t ip[16];
uint8_t ip[16];
uint32_t as;
uint8_t type;
#ifdef CC_GCC
} __attribute__((packed));
#else
Expand Down Expand Up @@ -239,6 +246,7 @@ struct dump_announce4
uint8_t mask;
uint32_t prefix;
uint8_t origin;
uint32_t nexthop;
uint8_t aspathlen;
uint16_t communitylen;
uint16_t extcommunitylen4;
Expand All @@ -263,6 +271,7 @@ struct dump_announce6
uint8_t mask;
uint8_t prefix[16];
uint8_t origin;
uint8_t nexthop[16];
uint8_t aspathlen;
uint16_t communitylen;
uint16_t extcommunitylen6;
Expand Down Expand Up @@ -386,6 +395,7 @@ struct peer_t
uint8_t allow;
uint8_t newallow; /* to avoid peer drop during reconfiguration */
uint8_t status; /* 0 offline, 1 connected, 2 authed */
uint8_t type; /* iBGP/eBGP */
uint32_t ucount; /* bgp updates count */
union {
struct in6_addr ip6; /* peer IPv4 address */
Expand Down
30 changes: 15 additions & 15 deletions inc/p_dump.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*******************************************************************************/
/* */
/* Copyright 2004-2017 Pascal Gloor */
/* Copyright 2004-2017 Pascal Gloor */
/* */
/* Licensed under the Apache License, Version 2.0 (the "License"); */
/* you may not use this file except in compliance with the License. */
Expand All @@ -17,32 +17,32 @@
/*******************************************************************************/


void p_dump_open_file (struct peer_t *peer, int id, uint64_t ts);
void p_dump_add_open (struct peer_t *peer, int id, uint64_t ts);
void p_dump_add_close (struct peer_t *peer, int id, uint64_t ts);
void p_dump_add_keepalive (struct peer_t *peer, int id, uint64_t ts);
void p_dump_add_header4 (struct peer_t *peer, int id, uint64_t ts);
void p_dump_add_header6 (struct peer_t *peer, int id, uint64_t ts);
void p_dump_add_footer (struct peer_t *peer, int id, uint64_t ts);
void p_dump_check_file (struct peer_t *peer, int id, uint64_t ts);
void p_dump_open_file (struct peer_t *peer, int id, struct timeval *ts);
void p_dump_add_open (struct peer_t *peer, int id, struct timeval *ts);
void p_dump_add_close (struct peer_t *peer, int id, struct timeval *ts);
void p_dump_add_keepalive (struct peer_t *peer, int id, struct timeval *ts);
void p_dump_add_header4 (struct peer_t *peer, int id, struct timeval *ts);
void p_dump_add_header6 (struct peer_t *peer, int id, struct timeval *ts);
void p_dump_add_footer (struct peer_t *peer, int id, struct timeval *ts);
void p_dump_check_file (struct peer_t *peer, int id, struct timeval *ts);
void p_dump_close_file (struct peer_t *peer, int id);

void p_dump_add_withdrawn4 (struct peer_t *peer, int id, uint64_t ts,
void p_dump_add_withdrawn4 (struct peer_t *peer, int id, struct timeval *ts,
uint32_t prefix, uint8_t mask);
void p_dump_add_withdrawn6 (struct peer_t *peer, int id, uint64_t ts,
void p_dump_add_withdrawn6 (struct peer_t *peer, int id, struct timeval *ts,
uint8_t prefix[16], uint8_t mask);

void p_dump_add_announce4 (struct peer_t *peer, int id, uint64_t ts,
void p_dump_add_announce4 (struct peer_t *peer, int id, struct timeval *ts,
uint32_t prefix, uint8_t mask,
uint8_t origin,
uint8_t origin, uint32_t nexthop,
void *aspath, uint16_t aspathlen,
void *community, uint16_t communitylen,
void *extcommunity4, uint16_t extcommunitylen4,
void *largecommunity, uint16_t largecommunitylen );

void p_dump_add_announce6 (struct peer_t *peer, int id, uint64_t ts,
void p_dump_add_announce6 (struct peer_t *peer, int id, struct timeval *ts,
uint8_t prefix[16], uint8_t mask,
uint8_t origin,
uint8_t origin, uint8_t nexthop[16],
void *aspath, uint16_t aspathlen,
void *community, uint16_t communitylen,
void *extcommunity6, uint16_t extcommunitylen6,
Expand Down
2 changes: 2 additions & 0 deletions inc/p_ptoa.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ int main(int argc, char *argv[]);
// void mytime(time_t ts);
void syntax(char *prog);
void print_origin(int mode, uint8_t origin);
void print_nexthop4(int mode, uint32_t nexthop);
void print_nexthop6(int mode, uint8_t nexthop[16]);
void print_aspath(int mode, struct dump_announce_aspath *aspath, uint8_t len);
void print_community(int mode, struct dump_announce_community *community, uint16_t len);
void print_extcommunity4(int mode, struct dump_announce_extcommunity4 *com, uint16_t len);
Expand Down
2 changes: 1 addition & 1 deletion inc/p_tools.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ char *p_tools_ip6str(int peerid, struct in6_addr *ip);

void p_tools_dump(const char *desc, char *data, int len);

void p_tools_humantime(char *line, size_t len, time_t ts);
void p_tools_humantime(char *line, size_t len, struct timeval *ts);
11 changes: 10 additions & 1 deletion src/p_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ int p_config_load(struct config_t *config, struct peer_t *peer, uint32_t mytime)
config->export |= EXPORT_EXTCOMMUNITY;
else if ( ! strcmp(s, "largecommunity") )
config->export |= EXPORT_LARGECOMMUNITY;
else if ( ! strcmp(s, "nexthop") )
config->export |= EXPORT_NEXT_HOP;
#ifdef DEBUG
else
printf("DEBUG: Unknown export %s\n", s);
Expand Down Expand Up @@ -275,11 +277,18 @@ int p_config_load(struct config_t *config, struct peer_t *peer, uint32_t mytime)

fclose(fd);

/* clearning no more allowed peers */

/* clearning no more allowed peers *
* and set session type (eBGP/iBGP) */
{
int a;
for(a=0; a<MAX_PEERS; a++)
{
if ( peer[a].as == config->as )
peer[a].type = BGP_TYPE_IBGP;
else
peer[a].type = BGP_TYPE_EBGP;

if ( peer[a].newallow == 0 )
{
peer[a].status = 0;
Expand Down
Loading

0 comments on commit 3fcbd36

Please sign in to comment.