From 7e662857d9cf50de2b81c156dbdeb95e579291a0 Mon Sep 17 00:00:00 2001 From: Alexandre Snarskii Date: Mon, 7 Oct 2013 18:24:27 +0400 Subject: [PATCH] -4 option added. Thanks to Martin J. Levy. --- .gitignore | 4 ++++ CHANGES | 4 +++- README.md | 4 ++++ bgpq3.8 | 6 ++++-- bgpq3.c | 22 ++++++++++++++++++---- 5 files changed, 33 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 640827a..3aa3e92 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,7 @@ CVS/ Makefile config.h +*.o +bgpq3 +config.log +config.status diff --git a/CHANGES b/CHANGES index 32dc0b9..f8748a9 100644 --- a/CHANGES +++ b/CHANGES @@ -1,5 +1,7 @@ -0.1.20 (2013-10-07) +0.1.20-todo (2013-10-07) - socket close code fixed. Thanks to Martin J. Levy. + - new flag -4, "force ipv4". Actually does a little more than allowing + for pedantic checks. Thanks to Martin J. Levy. 0.1.19 (2013-05-09) - CLANG compilation issues fixed. diff --git a/README.md b/README.md index e5bbbcc..86024aa 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,10 @@ The options are as follows: > assume that your device is asn32-capable. +- -4 + + > generate IPv4 prefix/access-lists (default). + - -6 > generate IPv6 prefix/access-lists (IPv4 by default). diff --git a/bgpq3.8 b/bgpq3.8 index f4c4902..ca9f8a9 100644 --- a/bgpq3.8 +++ b/bgpq3.8 @@ -1,4 +1,4 @@ -.\" Copyright (c) 2007-2011 Alexandre Snarskii +.\" Copyright (c) 2007-2013 Alexandre Snarskii .\" All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without @@ -38,7 +38,7 @@ .Fl f Ar asn | .Fl G Ar asn .Oc -.Op Fl 36ADdJjX +.Op Fl 346ADdJjX .Op Fl R Ar len .Op Fl m Ar max .Ar OBJECTS @@ -53,6 +53,8 @@ The options are as follows: .Bl -tag -width Ds .It Fl 3 assume that your device is asn32-safe. +.It Fl 4 +generate IPv4 prefix/access-lists (default). .It Fl 6 generate IPv6 prefix/access-lists (IPv4 by default). .It Fl A diff --git a/bgpq3.c b/bgpq3.c index d424157..a4d3799 100644 --- a/bgpq3.c +++ b/bgpq3.c @@ -24,8 +24,9 @@ int usage(int ecode) { printf("\nUsage: bgpq3 [-h host] [-S sources] [-P|E|G |f ]" - " [-36ADJjXd] [-R len] ...\n"); + " [-346ADJjXd] [-R len] ...\n"); printf(" -3 : assume that your device is asn32-safe\n"); + printf(" -4 : generate IPv4 prefix-lists (default)\n"); printf(" -6 : generate IPv6 prefix-lists (IPv4 by default)\n"); printf(" -A : try to aggregate Cisco prefix-lists or Juniper " "route-filters\n as much as possible\n"); @@ -112,19 +113,32 @@ main(int argc, char* argv[]) { int c; struct bgpq_expander expander; - int af=AF_INET; + int af=AF_INET, selectedipv4 = 0; int widthSet=0, aggregate=0, refine=0; unsigned long maxlen=0; bgpq_expander_init(&expander,af); expander.sources=getenv("IRRD_SOURCES"); - while((c=getopt(argc,argv,"36AdDES:jJf:l:m:M:W:PR:G:Th:X"))!=EOF) { + while((c=getopt(argc,argv,"346AdDES:jJf:l:m:M:W:PR:G:Th:X"))!=EOF) { switch(c) { case '3': expander.asn32=1; break; - case '6': af=AF_INET6; + case '4': + /* do nothing, expander already configured for IPv4 */ + if (expander.family == AF_INET6) { + sx_report(SX_FATAL, "-4 and -6 are mutually exclusive\n"); + exit(1); + }; + selectedipv4=1; + break; + case '6': + if (selectedipv4) { + sx_report(SX_FATAL, "-4 and -6 are mutually exclusive\n"); + exit(1); + }; + af=AF_INET6; expander.family=AF_INET6; expander.tree->family=AF_INET6; break;