Skip to content

Commit 3fcbd36

Browse files
authored
Merge pull request #10 from spale75/dev
release v1.1.3
2 parents 3f6764e + 1aede9a commit 3fcbd36

12 files changed

+218
-85
lines changed

README.md

+7-6
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ Piranha has one configuration file located in <destination folder>/etc/pir
132132

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

163164
### Start/Stop/Restart
164165

165-
<install dir>/etc/piranhactl <start|restart|stop>
166+
<install dir>/bin/piranhactl <start|restart|stop>
166167

167168
### Status (state of all neighbors)
168169

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

188189
#### Human readable format
189190

190-
2017-10-21 21:31:54 peer ip 2a03:2260::5 AS 201701
191+
2017-10-21 21:31:54 peer ip 2a03:2260::5 AS 201701 TYPE eBGP
191192
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
192193
2017-10-21 21:31:55 eof
193194

194195
#### Machine readable format
195196

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

200201
#### JSON format
201202
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.
202203

203-
{ "timestamp": 1508621514, "type": "peer", "msg": { "peer": { "proto": "ipv6", "ip": "2a03:2260::5", "asn": 201701 } } }
204-
{ "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" ] } }
204+
{ "timestamp": 1508621514, "type": "peer", "msg": { "peer": { "proto": "ipv6", "ip": "2a03:2260::5", "asn": 201701, "type": "eBGP" } } }
205+
{ "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" ] } }
205206
{ "timestamp": 1508621515, "type": "footer" }
206207

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

inc/p_defs.h

+11-1
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,15 @@
103103
#define BGP_ORIGIN_EGP 1
104104
#define BGP_ORIGIN_UNKN 2
105105

106+
#define BGP_TYPE_IBGP 0
107+
#define BGP_TYPE_EBGP 1
108+
106109
#define EXPORT_ORIGIN 0x01
107110
#define EXPORT_ASPATH 0x02
108111
#define EXPORT_COMMUNITY 0x04
109112
#define EXPORT_EXTCOMMUNITY 0x08
110113
#define EXPORT_LARGECOMMUNITY 0x10
114+
#define EXPORT_NEXT_HOP 0x20
111115

112116
#define DUMP_OPEN 10
113117
#define DUMP_CLOSE 11
@@ -188,6 +192,7 @@ struct dump_msg
188192
uint8_t type;
189193
uint16_t len;
190194
uint64_t ts;
195+
uint64_t uts;
191196
#ifdef CC_GCC
192197
} __attribute__((packed));
193198
#else
@@ -198,6 +203,7 @@ struct dump_header4
198203
{
199204
uint32_t ip;
200205
uint32_t as;
206+
uint8_t type;
201207
#ifdef CC_GCC
202208
} __attribute__((packed));
203209
#else
@@ -206,8 +212,9 @@ struct dump_header4
206212

207213
struct dump_header6
208214
{
209-
uint8_t ip[16];
215+
uint8_t ip[16];
210216
uint32_t as;
217+
uint8_t type;
211218
#ifdef CC_GCC
212219
} __attribute__((packed));
213220
#else
@@ -239,6 +246,7 @@ struct dump_announce4
239246
uint8_t mask;
240247
uint32_t prefix;
241248
uint8_t origin;
249+
uint32_t nexthop;
242250
uint8_t aspathlen;
243251
uint16_t communitylen;
244252
uint16_t extcommunitylen4;
@@ -263,6 +271,7 @@ struct dump_announce6
263271
uint8_t mask;
264272
uint8_t prefix[16];
265273
uint8_t origin;
274+
uint8_t nexthop[16];
266275
uint8_t aspathlen;
267276
uint16_t communitylen;
268277
uint16_t extcommunitylen6;
@@ -386,6 +395,7 @@ struct peer_t
386395
uint8_t allow;
387396
uint8_t newallow; /* to avoid peer drop during reconfiguration */
388397
uint8_t status; /* 0 offline, 1 connected, 2 authed */
398+
uint8_t type; /* iBGP/eBGP */
389399
uint32_t ucount; /* bgp updates count */
390400
union {
391401
struct in6_addr ip6; /* peer IPv4 address */

inc/p_dump.h

+15-15
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*******************************************************************************/
22
/* */
3-
/* Copyright 2004-2017 Pascal Gloor */
3+
/* Copyright 2004-2017 Pascal Gloor */
44
/* */
55
/* Licensed under the Apache License, Version 2.0 (the "License"); */
66
/* you may not use this file except in compliance with the License. */
@@ -17,32 +17,32 @@
1717
/*******************************************************************************/
1818

1919

20-
void p_dump_open_file (struct peer_t *peer, int id, uint64_t ts);
21-
void p_dump_add_open (struct peer_t *peer, int id, uint64_t ts);
22-
void p_dump_add_close (struct peer_t *peer, int id, uint64_t ts);
23-
void p_dump_add_keepalive (struct peer_t *peer, int id, uint64_t ts);
24-
void p_dump_add_header4 (struct peer_t *peer, int id, uint64_t ts);
25-
void p_dump_add_header6 (struct peer_t *peer, int id, uint64_t ts);
26-
void p_dump_add_footer (struct peer_t *peer, int id, uint64_t ts);
27-
void p_dump_check_file (struct peer_t *peer, int id, uint64_t ts);
20+
void p_dump_open_file (struct peer_t *peer, int id, struct timeval *ts);
21+
void p_dump_add_open (struct peer_t *peer, int id, struct timeval *ts);
22+
void p_dump_add_close (struct peer_t *peer, int id, struct timeval *ts);
23+
void p_dump_add_keepalive (struct peer_t *peer, int id, struct timeval *ts);
24+
void p_dump_add_header4 (struct peer_t *peer, int id, struct timeval *ts);
25+
void p_dump_add_header6 (struct peer_t *peer, int id, struct timeval *ts);
26+
void p_dump_add_footer (struct peer_t *peer, int id, struct timeval *ts);
27+
void p_dump_check_file (struct peer_t *peer, int id, struct timeval *ts);
2828
void p_dump_close_file (struct peer_t *peer, int id);
2929

30-
void p_dump_add_withdrawn4 (struct peer_t *peer, int id, uint64_t ts,
30+
void p_dump_add_withdrawn4 (struct peer_t *peer, int id, struct timeval *ts,
3131
uint32_t prefix, uint8_t mask);
32-
void p_dump_add_withdrawn6 (struct peer_t *peer, int id, uint64_t ts,
32+
void p_dump_add_withdrawn6 (struct peer_t *peer, int id, struct timeval *ts,
3333
uint8_t prefix[16], uint8_t mask);
3434

35-
void p_dump_add_announce4 (struct peer_t *peer, int id, uint64_t ts,
35+
void p_dump_add_announce4 (struct peer_t *peer, int id, struct timeval *ts,
3636
uint32_t prefix, uint8_t mask,
37-
uint8_t origin,
37+
uint8_t origin, uint32_t nexthop,
3838
void *aspath, uint16_t aspathlen,
3939
void *community, uint16_t communitylen,
4040
void *extcommunity4, uint16_t extcommunitylen4,
4141
void *largecommunity, uint16_t largecommunitylen );
4242

43-
void p_dump_add_announce6 (struct peer_t *peer, int id, uint64_t ts,
43+
void p_dump_add_announce6 (struct peer_t *peer, int id, struct timeval *ts,
4444
uint8_t prefix[16], uint8_t mask,
45-
uint8_t origin,
45+
uint8_t origin, uint8_t nexthop[16],
4646
void *aspath, uint16_t aspathlen,
4747
void *community, uint16_t communitylen,
4848
void *extcommunity6, uint16_t extcommunitylen6,

inc/p_ptoa.h

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ int main(int argc, char *argv[]);
2323
// void mytime(time_t ts);
2424
void syntax(char *prog);
2525
void print_origin(int mode, uint8_t origin);
26+
void print_nexthop4(int mode, uint32_t nexthop);
27+
void print_nexthop6(int mode, uint8_t nexthop[16]);
2628
void print_aspath(int mode, struct dump_announce_aspath *aspath, uint8_t len);
2729
void print_community(int mode, struct dump_announce_community *community, uint16_t len);
2830
void print_extcommunity4(int mode, struct dump_announce_extcommunity4 *com, uint16_t len);

inc/p_tools.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ char *p_tools_ip6str(int peerid, struct in6_addr *ip);
99

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

12-
void p_tools_humantime(char *line, size_t len, time_t ts);
12+
void p_tools_humantime(char *line, size_t len, struct timeval *ts);

src/p_config.c

+10-1
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,8 @@ int p_config_load(struct config_t *config, struct peer_t *peer, uint32_t mytime)
192192
config->export |= EXPORT_EXTCOMMUNITY;
193193
else if ( ! strcmp(s, "largecommunity") )
194194
config->export |= EXPORT_LARGECOMMUNITY;
195+
else if ( ! strcmp(s, "nexthop") )
196+
config->export |= EXPORT_NEXT_HOP;
195197
#ifdef DEBUG
196198
else
197199
printf("DEBUG: Unknown export %s\n", s);
@@ -275,11 +277,18 @@ int p_config_load(struct config_t *config, struct peer_t *peer, uint32_t mytime)
275277

276278
fclose(fd);
277279

278-
/* clearning no more allowed peers */
280+
281+
/* clearning no more allowed peers *
282+
* and set session type (eBGP/iBGP) */
279283
{
280284
int a;
281285
for(a=0; a<MAX_PEERS; a++)
282286
{
287+
if ( peer[a].as == config->as )
288+
peer[a].type = BGP_TYPE_IBGP;
289+
else
290+
peer[a].type = BGP_TYPE_EBGP;
291+
283292
if ( peer[a].newallow == 0 )
284293
{
285294
peer[a].status = 0;

0 commit comments

Comments
 (0)