From 67e5d67651bd94b52e33442308158a415e43f39f Mon Sep 17 00:00:00 2001 From: Martin Winter Date: Fri, 3 Feb 2017 18:09:36 +0700 Subject: [PATCH 01/27] ospfd: Fix Coverity Warning CID 1399480 (#1 of 1): Buffer not null terminated (BUFFER_SIZE_WARNING) Coverity: buffer_size_warning: Calling strncpy with a maximum size argument of 100 bytes on destination array pid_file of size 100 bytes might leave the destination string unterminated. Signed-off-by: Martin Winter --- ospfd/ospf_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ospfd/ospf_main.c b/ospfd/ospf_main.c index 845d96032b..cc335a8abd 100644 --- a/ospfd/ospf_main.c +++ b/ospfd/ospf_main.c @@ -383,7 +383,7 @@ main (int argc, char **argv) pid_file[0] = '\0'; snprintf(pidfile_temp, sizeof(pidfile_temp), "%s/ospfd-%d.pid", pid_file, instance ); - strncpy(pid_file, pidfile_temp, sizeof(pid_file)); + strlcpy(pid_file, pidfile_temp, sizeof(pid_file)); } /* Process id file create. */ pid_output (pid_file); From fa389c272f944d15f31bb21d6d1ab0c53877f30c Mon Sep 17 00:00:00 2001 From: Martin Winter Date: Fri, 10 Feb 2017 16:51:57 +0700 Subject: [PATCH 02/27] vtysh: Fix Coverity Warning CID 1399479 (#1 of 1): Destination buffer too small (BUFFER_SIZE) Coverity: buffer_size: You might overrun the 108 byte destination string addr.sun_path by writing the maximum 4095 bytes from path. Signed-off-by: Martin Winter --- vtysh/vtysh.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vtysh/vtysh.c b/vtysh/vtysh.c index 7546b4ddb0..1b0dd8cd29 100644 --- a/vtysh/vtysh.c +++ b/vtysh/vtysh.c @@ -3001,7 +3001,7 @@ vtysh_connect (struct vtysh_client *vclient) memset (&addr, 0, sizeof (struct sockaddr_un)); addr.sun_family = AF_UNIX; - strncpy (addr.sun_path, path, strlen (path)); + strlcpy (addr.sun_path, path, sizeof (addr.sun_path)); #ifdef HAVE_STRUCT_SOCKADDR_UN_SUN_LEN len = addr.sun_len = SUN_LEN(&addr); #else From 4fdeb6b0af300af4522f7b46523c878ee2809d4a Mon Sep 17 00:00:00 2001 From: Martin Winter Date: Fri, 3 Feb 2017 18:30:59 +0700 Subject: [PATCH 03/27] zebra: Fix CID 1399335 (#1 of 1): Wrong sizeof argument (SIZEOF_MISMATCH) Needs to be size of correct structure (prefix instead of prefix_ipv4) Signed-off-by: Martin Winter --- zebra/zserv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zebra/zserv.c b/zebra/zserv.c index 83d7d0f811..8618e5c371 100644 --- a/zebra/zserv.c +++ b/zebra/zserv.c @@ -1188,7 +1188,7 @@ zread_ipv4_delete (struct zserv *client, u_short length, struct zebra_vrf *zvrf) api.safi = stream_getw (s); /* IPv4 prefix. */ - memset (&p, 0, sizeof (struct prefix_ipv4)); + memset (&p, 0, sizeof (struct prefix)); p.family = AF_INET; p.prefixlen = stream_getc (s); stream_get (&p.u.prefix4, s, PSIZE (p.prefixlen)); From b3411578b063894892d469dfda8cad02a2ecd0ed Mon Sep 17 00:00:00 2001 From: Martin Winter Date: Fri, 3 Feb 2017 18:37:48 +0700 Subject: [PATCH 04/27] lib: CID 1399296: Assign instead of compare (PW.ASSIGN_WHERE_COMPARE_MEANT) Needs to be a comparison, not assignment Signed-off-by: Martin Winter --- lib/thread.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/thread.c b/lib/thread.c index 5b8778b717..e10d0c48bf 100644 --- a/lib/thread.c +++ b/lib/thread.c @@ -828,7 +828,7 @@ funcname_thread_add_read_write (int dir, struct thread_master *m, #else if (FD_ISSET (fd, fdset)) { - zlog (NULL, LOG_WARNING, "There is already %s fd [%d]", (dir = THREAD_READ) ? "read" : "write", fd); + zlog (NULL, LOG_WARNING, "There is already %s fd [%d]", (dir == THREAD_READ) ? "read" : "write", fd); return NULL; } From 9cbad1d7c462035d3e561347f6f62d85b1a8f33a Mon Sep 17 00:00:00 2001 From: Martin Winter Date: Fri, 3 Feb 2017 23:05:11 +0700 Subject: [PATCH 05/27] ospfd: CID 1399387 (#1 of 2): Destination buffer too small (STRING_OVERFLOW) Coverity: string_overflow: You might overrun the 100-character destination string vty_path by writing 4096 characters from vty_sock_path. Signed-off-by: Martin Winter --- ospfd/ospf_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ospfd/ospf_main.c b/ospfd/ospf_main.c index cc335a8abd..edb1ca470e 100644 --- a/ospfd/ospf_main.c +++ b/ospfd/ospf_main.c @@ -407,7 +407,7 @@ main (int argc, char **argv) } else { - strcpy(vty_path, vty_sock_path); + strlcpy(vty_path, vty_sock_path, sizeof(vty_path)); } vty_serv_sock (vty_addr, vty_port, vty_path); From 5a1218aa53d2b3744f93729e1d0d16898b7c4eda Mon Sep 17 00:00:00 2001 From: Christian Franke Date: Fri, 3 Feb 2017 16:53:47 +0100 Subject: [PATCH 06/27] tests: remove dejagnu Signed-off-by: Christian Franke --- configure.ac | 14 --- tests/bgpd.tests/Makefile.am | 7 -- tests/bgpd.tests/aspathtest.exp | 76 ------------- tests/bgpd.tests/ecommtest.exp | 13 --- tests/bgpd.tests/testbgpcap.exp | 51 --------- tests/bgpd.tests/testbgpmpath.exp | 12 --- tests/bgpd.tests/testbgpmpattr.exp | 38 ------- tests/config/unix.exp | 102 ------------------ tests/global-conf.exp | 0 tests/lib/bgpd.exp | 0 tests/lib/libfrr.exp | 0 tests/libfrr.tests/Makefile.am | 6 -- tests/libfrr.tests/tabletest.exp | 9 -- tests/libfrr.tests/test-timer-correctness.exp | 7 -- tests/libfrr.tests/testcli.exp | 23 ---- tests/libfrr.tests/testcommands.exp | 31 ------ tests/libfrr.tests/testnexthopiter.exp | 8 -- tests/libfrr.tests/teststream.exp | 28 ----- 18 files changed, 425 deletions(-) delete mode 100644 tests/bgpd.tests/Makefile.am delete mode 100644 tests/bgpd.tests/aspathtest.exp delete mode 100644 tests/bgpd.tests/ecommtest.exp delete mode 100644 tests/bgpd.tests/testbgpcap.exp delete mode 100644 tests/bgpd.tests/testbgpmpath.exp delete mode 100644 tests/bgpd.tests/testbgpmpattr.exp delete mode 100644 tests/config/unix.exp delete mode 100644 tests/global-conf.exp delete mode 100644 tests/lib/bgpd.exp delete mode 100644 tests/lib/libfrr.exp delete mode 100644 tests/libfrr.tests/Makefile.am delete mode 100644 tests/libfrr.tests/tabletest.exp delete mode 100644 tests/libfrr.tests/test-timer-correctness.exp delete mode 100644 tests/libfrr.tests/testcli.exp delete mode 100644 tests/libfrr.tests/testcommands.exp delete mode 100644 tests/libfrr.tests/testnexthopiter.exp delete mode 100644 tests/libfrr.tests/teststream.exp diff --git a/configure.ac b/configure.ac index cd88e30c78..4390539918 100755 --- a/configure.ac +++ b/configure.ac @@ -1497,18 +1497,6 @@ dnl ---------- CONFDATE=`date '+%Y%m%d'` AC_SUBST(CONFDATE) -dnl ------- -dnl DejaGNU -dnl ------- -if test x"$DEJAGNU" = x -then - DEJAGNU="\$(top_srcdir)/tests/global-conf.exp" -fi -RUNTESTDEFAULTFLAGS="-x --tool \$\$tool" - -AC_SUBST(DEJAGNU) -AC_SUBST(RUNTESTDEFAULTFLAGS) - dnl ------------------------------ dnl set paths for state directory dnl ------------------------------ @@ -1610,8 +1598,6 @@ AC_CONFIG_FILES([Makefile lib/Makefile qpb/Makefile zebra/Makefile ripd/Makefile ospf6d/Makefile ldpd/Makefile isisd/Makefile vtysh/Makefile doc/Makefile ospfclient/Makefile tests/Makefile m4/Makefile pimd/Makefile - tests/bgpd.tests/Makefile - tests/libfrr.tests/Makefile redhat/Makefile tools/Makefile cumulus/Makefile diff --git a/tests/bgpd.tests/Makefile.am b/tests/bgpd.tests/Makefile.am deleted file mode 100644 index 5900186cf5..0000000000 --- a/tests/bgpd.tests/Makefile.am +++ /dev/null @@ -1,7 +0,0 @@ -EXTRA_DIST = \ - aspathtest.exp \ - ecommtest.exp \ - testbgpcap.exp \ - testbgpmpath.exp \ - testbgpmpattr.exp - diff --git a/tests/bgpd.tests/aspathtest.exp b/tests/bgpd.tests/aspathtest.exp deleted file mode 100644 index f5f262f80a..0000000000 --- a/tests/bgpd.tests/aspathtest.exp +++ /dev/null @@ -1,76 +0,0 @@ -set timeout 10 -set testprefix "aspathtest " -set aborted 0 -set color 1 - -spawn sh -c "exec ./aspathtest 2>/dev/null" - -# proc onetest { test_name note start } { -# proc headerline { line } { - -set parserno 0 -proc parsertest { test_name } { - global parserno - headerline "test $parserno" - onetest "parse $test_name" " ($parserno)" "$test_name:" - onetest "parse $test_name +empty_prepend" " (#$parserno)" "empty prepend $test_name:" - incr parserno 1 -} -set attrno 0 -proc attrtest { test_name } { - global attrno - headerline "aspath_attr test $attrno" - onetest "attr $test_name" " (#$attrno)" "$test_name" - incr attrno 1 -} - - -parsertest "seq1" -parsertest "seq2" -parsertest "seq3" -parsertest "seqset" -parsertest "seqset2" -parsertest "multi" -parsertest "confed" -parsertest "confed2" -parsertest "confset" -parsertest "confmulti" -parsertest "seq4" -parsertest "tripleseq1" -parsertest "someprivate" -parsertest "allprivate" -parsertest "long" -parsertest "seq1extra" -parsertest "empty" -parsertest "redundantset" -parsertest "reconcile_lead_asp" -parsertest "reconcile_new_asp" -parsertest "reconcile_confed" -parsertest "reconcile_start_trans" -parsertest "reconcile_start_trans4" -parsertest "reconcile_start_trans_error" -parsertest "redundantset2" -parsertest "zero-size overflow" -parsertest "zero-size overflow + valid segment" -parsertest "invalid segment type" - -for {set i 0} {$i < 10} {incr i 1} { onetest "prepend $i" "" "prepend test $i"; } -for {set i 0} {$i < 5} {incr i 1} { onetest "aggregate $i" "" "aggregate test $i"; } -for {set i 0} {$i < 5} {incr i 1} { onetest "reconcile $i" "" "reconcile test $i"; } -for {set i 0} {$i < 22} {incr i 1} { onetest "compare $i" "" "left cmp "; } - -onetest "empty_get" "" "empty_get_test" -attrtest "basic test" -attrtest "length too short" -attrtest "length too long" -attrtest "incorrect flag" -attrtest "as4_path, with as2 format data" -attrtest "as4, with incorrect attr length" -attrtest "basic 4-byte as-path" -attrtest "4b AS_PATH: too short" -attrtest "4b AS_PATH: too long" -attrtest "4b AS_PATH: too long2" -attrtest "4b AS_PATH: bad flags" -attrtest "4b AS4_PATH w/o AS_PATH" -attrtest "4b AS4_PATH: confed" - diff --git a/tests/bgpd.tests/ecommtest.exp b/tests/bgpd.tests/ecommtest.exp deleted file mode 100644 index cbeb03af52..0000000000 --- a/tests/bgpd.tests/ecommtest.exp +++ /dev/null @@ -1,13 +0,0 @@ -set timeout 10 -set testprefix "ecommtest " -set aborted 0 -set color 0 - -spawn sh -c "exec ./ecommtest 2>/dev/null" - -# proc simpletest { start } { - -simpletest "ipaddr" -simpletest "ipaddr-so" -simpletest "asn" -simpletest "asn4" diff --git a/tests/bgpd.tests/testbgpcap.exp b/tests/bgpd.tests/testbgpcap.exp deleted file mode 100644 index aba6906bc0..0000000000 --- a/tests/bgpd.tests/testbgpcap.exp +++ /dev/null @@ -1,51 +0,0 @@ -set timeout 10 -set testprefix "testbgpcap " -set aborted 0 -set color 1 - -spawn sh -c "exec ./testbgpcap 2>/dev/null" - -# proc simpletest { start } { - -simpletest "MP4: MP IP/Uni" -simpletest "MPv6: MP IPv6/Uni" -simpletest "MP2: MP IP/Multicast" -simpletest "MP3: MP IP6/MPLS-labeled VPN" -simpletest "MP5: MP IP6/MPLS-VPN" -simpletest "MP6: MP IP4/MPLS-laveled VPN" -simpletest "MP8: MP unknown AFI/SAFI" -simpletest "MP-short: MP IP4/Unicast, length too short (< minimum)" -simpletest "MP-overflow: MP IP4/Unicast, length too long" -simpletest "caphdr: capability header, and no more" -simpletest "nodata: header, no data but length says there is" -simpletest "padded: valid, with padding" -simpletest "minsize: violates minsize requirement" -simpletest "ORF: ORF, simple, single entry, single tuple" -simpletest "ORF-many: ORF, multi entry/tuple" -simpletest "ORFlo: ORF, multi entry/tuple, hdr length too short" -simpletest "ORFlu: ORF, multi entry/tuple, length too long" -simpletest "ORFnu: ORF, multi entry/tuple, entry number too long" -simpletest "ORFno: ORF, multi entry/tuple, entry number too short" -simpletest "ORFpad: ORF, multi entry/tuple, padded to align" -simpletest "AS4: AS4 capability" -simpletest "GR: GR capability" -simpletest "GR-short: GR capability, but header length too short" -simpletest "GR-long: GR capability, but header length too long" -simpletest "GR-trunc: GR capability, but truncated" -simpletest "GR-empty: GR capability, but empty." -simpletest "MP-empty: MP capability, but empty." -simpletest "ORF-empty: ORF capability, but empty." -simpletest "AS4-empty: AS4 capability, but empty." -simpletest "dyn-empty: Dynamic capability, but empty." -simpletest "dyn-old: Dynamic capability (deprecated version)" -simpletest "Cap-singlets: One capability per Optional-Param" -simpletest "Cap-series: Series of capability, one Optional-Param" -simpletest "AS4more: AS4 capability after other caps (singlets)" -simpletest "AS4series: AS4 capability, in series of capabilities" -simpletest "AS4real: AS4 capability, in series of capabilities" -simpletest "AS4real2: AS4 capability, in series of capabilities" -simpletest "DynCap: Dynamic Capability Message, IP/Multicast" -simpletest "DynCapLong: Dynamic Capability Message, IP/Multicast, truncated" -simpletest "DynCapPadded: Dynamic Capability Message, IP/Multicast, padded" -simpletest "DynCapMPCpadded: Dynamic Capability Message, IP/Multicast, cap data padded" -simpletest "DynCapMPCoverflow: Dynamic Capability Message, IP/Multicast, cap data != length" diff --git a/tests/bgpd.tests/testbgpmpath.exp b/tests/bgpd.tests/testbgpmpath.exp deleted file mode 100644 index 6820f636a4..0000000000 --- a/tests/bgpd.tests/testbgpmpath.exp +++ /dev/null @@ -1,12 +0,0 @@ -set timeout 10 -set testprefix "testbgpmpath " -set aborted 0 -set color 1 - -spawn sh -c "exec ./testbgpmpath 2>/dev/null" - -# proc simpletest { start } { - -simpletest "bgp maximum-paths config" -simpletest "bgp_mp_list" -simpletest "bgp_info_mpath_update" diff --git a/tests/bgpd.tests/testbgpmpattr.exp b/tests/bgpd.tests/testbgpmpattr.exp deleted file mode 100644 index 1abce3fc9a..0000000000 --- a/tests/bgpd.tests/testbgpmpattr.exp +++ /dev/null @@ -1,38 +0,0 @@ -set timeout 10 -set testprefix "testbgpmpattr " -set aborted 0 -set color 1 - -spawn sh -c "exec ./testbgpmpattr 2>/dev/null" - -# proc simpletest { start } { - -simpletest "IPv6: IPV6 MP Reach, global nexthop, 1 NLRI" -simpletest "IPv6-2: IPV6 MP Reach, global nexthop, 2 NLRIs" -simpletest "IPv6-default: IPV6 MP Reach, global nexthop, 2 NLRIs + default" -simpletest "IPv6-lnh: IPV6 MP Reach, global+local nexthops, 2 NLRIs + default" -simpletest "IPv6-nhlen: IPV6 MP Reach, inappropriate nexthop length" -simpletest "IPv6-nhlen2: IPV6 MP Reach, invalid nexthop length" -simpletest "IPv6-nhlen3: IPV6 MP Reach, nexthop length overflow" -simpletest "IPv6-nhlen4: IPV6 MP Reach, nexthop length short" -simpletest "IPv6-nlri: IPV6 MP Reach, NLRI bitlen overflow" -simpletest "IPv4: IPv4 MP Reach, 2 NLRIs + default" -simpletest "IPv4-nhlen: IPv4 MP Reach, nexthop lenth overflow" -simpletest "IPv4-nlrilen: IPv4 MP Reach, nlri lenth overflow" -simpletest "IPv4-VPNv4: IPv4/VPNv4 MP Reach, RD, Nexthop, 2 NLRIs" -simpletest "IPv4-VPNv4-bogus-plen: IPv4/MPLS-labeled VPN MP Reach, RD, Nexthop, NLRI / bogus p'len" -simpletest "IPv4-VPNv4-plen1-short: IPv4/VPNv4 MP Reach, RD, Nexthop, 2 NLRIs, 1st plen short" -simpletest "IPv4-VPNv4-plen1-long: IPv4/VPNv4 MP Reach, RD, Nexthop, 2 NLRIs, 1st plen long" -simpletest "IPv4-VPNv4-plenn-long: IPv4/VPNv4 MP Reach, RD, Nexthop, 3 NLRIs, last plen long" -simpletest "IPv4-VPNv4-plenn-short: IPv4/VPNv4 MP Reach, RD, Nexthop, 2 NLRIs, last plen short" -simpletest "IPv4-VPNv4-bogus-rd-type: IPv4/VPNv4 MP Reach, RD, NH, 2 NLRI, unknown RD in 1st (log, but parse)" -simpletest "IPv4-VPNv4-0-nlri: IPv4/VPNv4 MP Reach, RD, Nexthop, 3 NLRI, 3rd 0 bogus" -simpletest "IPv6-bug: IPv6, global nexthop, 1 default NLRI" -simpletest "IPv6-unreach: IPV6 MP Unreach, 1 NLRI" -simpletest "IPv6-unreach2: IPV6 MP Unreach, 2 NLRIs" -simpletest "IPv6-unreach-default: IPV6 MP Unreach, 2 NLRIs + default" -simpletest "IPv6-unreach-nlri: IPV6 MP Unreach, NLRI bitlen overflow" -simpletest "IPv4-unreach: IPv4 MP Unreach, 2 NLRIs + default" -simpletest "IPv4-unreach-nlrilen: IPv4 MP Unreach, nlri length overflow" -simpletest "IPv4-unreach-VPNv4: IPv4/MPLS-labeled VPN MP Unreach, RD, 3 NLRIs" - diff --git a/tests/config/unix.exp b/tests/config/unix.exp deleted file mode 100644 index 2f6bceadbe..0000000000 --- a/tests/config/unix.exp +++ /dev/null @@ -1,102 +0,0 @@ - -# every test should always be run and always return some status. -# so, if we lose sync with a multi-test program, aborted will be used -# to flag the remainder of the tests as untested. -#set aborted 0 - -# only match with color codes since "failed" / "OK" might otherwise -# be part of the output... -#set color 1 - -set xfail 0 - -proc onesimple { test_name match } { - global verbose - global aborted - global testprefix - if { $aborted > 0 } { - untested "$testprefix$test_name" - return - } - if { $verbose > 0 } { - send_user "$testprefix$test_name$note\n" - } - expect { - "$match" { pass "$testprefix$test_name"; } - eof { fail "$testprefix$test_name"; set aborted 1; } - timeout { unresolved "$testprefix$test_name"; set aborted 1; } - } -} - -proc onetest { test_name note start } { - global aborted - global testprefix - global verbose - global color - global xfail - - if { $aborted > 0 } { - untested "$testprefix$test_name" - return - } - - if { $verbose > 0 } { - send_user "$testprefix$test_name$note\n" - } - expect { - "$start" { } - - eof { unresolved "$testprefix$test_name"; set aborted 1; } - timeout { unresolved "$testprefix$test_name"; set aborted 1; } - } - - if { $aborted > 0 } { - send_user "sync failed: $testprefix$test_name$note -- $testprefix aborted!\n" - return - } - - if { $color } { - set pat "(32mOK|31mfailed)" - } else { - set pat "(OK|failed)" - } - expect { - # need this because otherwise expect will skip over a "failed" and - # grab the next "OK" (or the other way around) - -re "$pat" { - if { "$expect_out(0,string)" == "32mOK" || "$expect_out(0,string)" == "OK" } { - pass "$testprefix$test_name" - } else { - if { $xfail } { - xfail "$testprefix$test_name" - } else { - fail "$testprefix$test_name" - } - } - return - } - - eof { unresolved "$testprefix$test_name"; set aborted 1; } - timeout { unresolved "$testprefix$test_name"; set aborted 1; } - } - - if { $aborted > 0 } { - send_user "failed: $testprefix$test_name$note -- $testprefix aborted!\n" - return - } -} - -proc headerline { line } { - global aborted - if { $aborted > 0 } { return; } - expect { - $line { return; } - eof { send_user "numbering mismatch!\n"; set aborted 1; } - timeout { send_user "numbering mismatch!\n"; set aborted 1; } - } -} - -proc simpletest { start } { - onetest "$start" "" "$start" -} - diff --git a/tests/global-conf.exp b/tests/global-conf.exp deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/tests/lib/bgpd.exp b/tests/lib/bgpd.exp deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/tests/lib/libfrr.exp b/tests/lib/libfrr.exp deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/tests/libfrr.tests/Makefile.am b/tests/libfrr.tests/Makefile.am deleted file mode 100644 index 4b74e2d3fb..0000000000 --- a/tests/libfrr.tests/Makefile.am +++ /dev/null @@ -1,6 +0,0 @@ -EXTRA_DIST = \ - tabletest.exp \ - test-timer-correctness.exp \ - testcommands.exp \ - testcli.exp \ - testnexthopiter.exp diff --git a/tests/libfrr.tests/tabletest.exp b/tests/libfrr.tests/tabletest.exp deleted file mode 100644 index 7496994b7f..0000000000 --- a/tests/libfrr.tests/tabletest.exp +++ /dev/null @@ -1,9 +0,0 @@ -set timeout 10 -set testprefix "tabletest " -set aborted 0 - -spawn sh -c "exec ./tabletest 2>/dev/null" - -for {set i 0} {$i < 6} {incr i 1} { onesimple "cmp $i" "Verifying cmp"; } -for {set i 0} {$i < 11} {incr i 1} { onesimple "succ $i" "Verifying successor"; } -onesimple "pause" "Verified pausing" diff --git a/tests/libfrr.tests/test-timer-correctness.exp b/tests/libfrr.tests/test-timer-correctness.exp deleted file mode 100644 index 570150cd51..0000000000 --- a/tests/libfrr.tests/test-timer-correctness.exp +++ /dev/null @@ -1,7 +0,0 @@ -set timeout 10 -set testprefix "test-timer-correctness" -set aborted 0 - -spawn sh -c "exec ./test-timer-correctness 2>/dev/null" - -onesimple "" "Expected output and actual output match." diff --git a/tests/libfrr.tests/testcli.exp b/tests/libfrr.tests/testcli.exp deleted file mode 100644 index 778bd0caa3..0000000000 --- a/tests/libfrr.tests/testcli.exp +++ /dev/null @@ -1,23 +0,0 @@ -set timeout 30 -set test_name "testcli" - -spawn sh -c "./testcli < $env(srcdir)/testcli.in | diff -au $env(srcdir)/testcli.refout -" - -expect { - eof { - } - timeout { - exp_close - fail "$test_name: timeout" - } -} - -catch wait result -set os_error [lindex $result 2] -set exit_status [lindex $result 3] - -if { $os_error == 0 && $exit_status == 0 } { - pass "$test_name" -} else { - fail "$test_name" -} diff --git a/tests/libfrr.tests/testcommands.exp b/tests/libfrr.tests/testcommands.exp deleted file mode 100644 index c5d5a00730..0000000000 --- a/tests/libfrr.tests/testcommands.exp +++ /dev/null @@ -1,31 +0,0 @@ -set timeout 30 -set test_name "testcommands" - -if {![info exists env(QUAGGA_TEST_COMMANDS)]} { - # sadly, the test randomly fails when configure parameters differ from - # what was used to create testcommands.refout. this can be fixed by - # shipping a matching vtysh_cmd.c, which we'll add after 0.99.23 - pass "$test_name" - return 0 -} - -spawn sh -c "./testcommands -e 0 < $env(srcdir)/testcommands.in | diff -au - $env(srcdir)/testcommands.refout" - -expect { - eof { - } - timeout { - exp_close - fail "$test_name: timeout" - } -} - -catch wait result -set os_error [lindex $result 2] -set exit_status [lindex $result 3] - -if { $os_error == 0 && $exit_status == 0 } { - pass "$test_name" -} else { - fail "$test_name" -} diff --git a/tests/libfrr.tests/testnexthopiter.exp b/tests/libfrr.tests/testnexthopiter.exp deleted file mode 100644 index 777b753995..0000000000 --- a/tests/libfrr.tests/testnexthopiter.exp +++ /dev/null @@ -1,8 +0,0 @@ -set timeout 10 -set testprefix "testnexthopiter " -set aborted 0 - -spawn sh -c "exec ./testnexthopiter 2>/dev/null" - -onesimple "simple" "Simple test passed." -onesimple "prng" "PRNG test passed." diff --git a/tests/libfrr.tests/teststream.exp b/tests/libfrr.tests/teststream.exp deleted file mode 100644 index c977bb4417..0000000000 --- a/tests/libfrr.tests/teststream.exp +++ /dev/null @@ -1,28 +0,0 @@ -set timeout 10 -spawn sh -c "exec ./teststream 2>/dev/null" - -expect { - "endp: 15, readable: 15, writeable: 1009" { } - eof { fail "teststream"; exit; } timeout { fail "teststream"; exit; } } -expect { - "0xef 0xbe 0xef 0xde 0xad 0xbe 0xef 0xde 0xad 0xbe 0xef 0xde 0xad 0xbe 0xef" { } - eof { fail "teststream"; exit; } timeout { fail "teststream"; exit; } } -expect { - "endp: 15, readable: 15, writeable: 0" { } - eof { fail "teststream"; exit; } timeout { fail "teststream"; exit; } } -expect { - "0xef 0xbe 0xef 0xde 0xad 0xbe 0xef 0xde 0xad 0xbe 0xef 0xde 0xad 0xbe 0xef" { } - eof { fail "teststream"; exit; } timeout { fail "teststream"; exit; } } -expect { - "c: 0xef" { } - eof { fail "teststream"; exit; } timeout { fail "teststream"; exit; } } -expect { - "w: 0xbeef" { } - eof { fail "teststream"; exit; } timeout { fail "teststream"; exit; } } -expect { - "l: 0xdeadbeef" { } - eof { fail "teststream"; exit; } timeout { fail "teststream"; exit; } } -expect { - "q: 0xdeadbeefdeadbeef" { } - eof { fail "teststream"; exit; } timeout { fail "teststream"; exit; } } -pass "teststream" From 30c48775607a8b0e277360e7d87a04b5a3356b80 Mon Sep 17 00:00:00 2001 From: Christian Franke Date: Fri, 3 Feb 2017 16:58:11 +0100 Subject: [PATCH 07/27] tests: reorganize tests hierarchically Signed-off-by: Christian Franke --- tests/.gitignore | 46 ++--- tests/Makefile.am | 163 ++++++++++-------- tests/{aspath_test.c => bgpd/test_aspath.c} | 0 .../test_capability.c} | 0 .../test_ecommunity.c} | 0 .../test_mp_attr.c} | 0 tests/{bgp_mpath_test.c => bgpd/test_mpath.c} | 0 tests/{ => helpers/c}/main.c | 0 tests/{ => helpers/c}/prng.c | 0 tests/{ => helpers/c}/prng.h | 0 tests/{ => helpers/c}/tests.h | 0 tests/{common-cli.c => lib/cli/common_cli.c} | 2 +- tests/{common-cli.h => lib/cli/common_cli.h} | 0 tests/{test-cli.c => lib/cli/test_cli.c} | 2 +- tests/{testcli.in => lib/cli/test_cli.in} | 0 .../cli/test_cli.refout} | 0 .../cli/test_commands.c} | 0 .../cli/test_commands.in} | 0 .../cli/test_commands.refout} | 0 tests/{test-buffer.c => lib/test_buffer.c} | 0 .../{test-checksum.c => lib/test_checksum.c} | 0 tests/{heavy.c => lib/test_heavy.c} | 0 .../test_heavy_thread.c} | 0 tests/{heavy-wq.c => lib/test_heavy_wq.c} | 0 tests/{test-memory.c => lib/test_memory.c} | 0 .../test_nexthop_iter.c} | 0 tests/{test-privs.c => lib/test_privs.c} | 0 tests/{test-segv.c => lib/test_segv.c} | 0 tests/{test-sig.c => lib/test_sig.c} | 0 tests/{test-stream.c => lib/test_stream.c} | 0 tests/lib/test_stream.refout | 8 + tests/{table_test.c => lib/test_table.c} | 0 .../test_timer_correctness.c} | 0 .../test_timer_performance.c} | 0 34 files changed, 124 insertions(+), 97 deletions(-) rename tests/{aspath_test.c => bgpd/test_aspath.c} (100%) rename tests/{bgp_capability_test.c => bgpd/test_capability.c} (100%) rename tests/{ecommunity_test.c => bgpd/test_ecommunity.c} (100%) rename tests/{bgp_mp_attr_test.c => bgpd/test_mp_attr.c} (100%) rename tests/{bgp_mpath_test.c => bgpd/test_mpath.c} (100%) rename tests/{ => helpers/c}/main.c (100%) rename tests/{ => helpers/c}/prng.c (100%) rename tests/{ => helpers/c}/prng.h (100%) rename tests/{ => helpers/c}/tests.h (100%) rename tests/{common-cli.c => lib/cli/common_cli.c} (98%) rename tests/{common-cli.h => lib/cli/common_cli.h} (100%) rename tests/{test-cli.c => lib/cli/test_cli.c} (98%) rename tests/{testcli.in => lib/cli/test_cli.in} (100%) rename tests/{testcli.refout => lib/cli/test_cli.refout} (100%) rename tests/{test-commands.c => lib/cli/test_commands.c} (100%) rename tests/{testcommands.in => lib/cli/test_commands.in} (100%) rename tests/{testcommands.refout => lib/cli/test_commands.refout} (100%) rename tests/{test-buffer.c => lib/test_buffer.c} (100%) rename tests/{test-checksum.c => lib/test_checksum.c} (100%) rename tests/{heavy.c => lib/test_heavy.c} (100%) rename tests/{heavy-thread.c => lib/test_heavy_thread.c} (100%) rename tests/{heavy-wq.c => lib/test_heavy_wq.c} (100%) rename tests/{test-memory.c => lib/test_memory.c} (100%) rename tests/{test-nexthop-iter.c => lib/test_nexthop_iter.c} (100%) rename tests/{test-privs.c => lib/test_privs.c} (100%) rename tests/{test-segv.c => lib/test_segv.c} (100%) rename tests/{test-sig.c => lib/test_sig.c} (100%) rename tests/{test-stream.c => lib/test_stream.c} (100%) create mode 100644 tests/lib/test_stream.refout rename tests/{table_test.c => lib/test_table.c} (100%) rename tests/{test-timer-correctness.c => lib/test_timer_correctness.c} (100%) rename tests/{test-timer-performance.c => lib/test_timer_performance.c} (100%) diff --git a/tests/.gitignore b/tests/.gitignore index 3002b27149..1642fa9493 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -16,26 +16,26 @@ TAGS *.xml .arch-inventory .arch-ids -aspathtest -ecommtest -heavy -heavythread -heavywq -tabletest -test-timer-correctness -test-timer-performance -testbgpcap -testbgpmpath -testbgpmpattr -testbuffer -testchecksum -testcli -testmemory -testprivs -testsegv -testsig -teststream -testnexthopiter -testcommands -test-commands-defun.c -site.exp +/bgpd/test_aspath +/bgpd/test_capability +/bgpd/test_ecommunity +/bgpd/test_mp_attr +/bgpd/test_mpath +/lib/cli/test_cli +/lib/cli/test_commands +/lib/cli/test_commands_defun.c +/lib/test_buffer +/lib/test_checksum +/lib/test_heavy +/lib/test_heavy_thread +/lib/test_heavy_wq +/lib/test_memory +/lib/test_nexthop_iter +/lib/test_privs +/lib/test_srcdest_table +/lib/test_segv +/lib/test_sig +/lib/test_stream +/lib/test_table +/lib/test_timer_correctness +/lib/test_timer_performance diff --git a/tests/Makefile.am b/tests/Makefile.am index 442635fb79..8b7ae57752 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,96 +1,115 @@ -AUTOMAKE_OPTIONS = dejagnu -DEJATOOL = libfrr - -SUBDIRS = \ - bgpd.tests \ - libfrr.tests - -EXTRA_DIST = \ - config/unix.exp \ - lib/bgpd.exp \ - lib/libfrr.exp \ - global-conf.exp \ - testcommands.in \ - testcommands.refout \ - testcli.in \ - testcli.refout - -AM_CPPFLAGS = -I.. -I$(top_srcdir) -I$(top_srcdir)/lib -I$(top_builddir)/lib +AUTOMAKE_OPTIONS = subdir-objects +AM_CPPFLAGS = \ + -I.. \ + -I$(top_srcdir) \ + -I$(top_srcdir)/lib \ + -I$(top_builddir)/lib \ + -I$(top_srcdir)/tests/helpers/c \ + -I$(top_builddir)/tests/helpers/c \ + -O DEFS = @DEFS@ $(LOCAL_OPTS) -DSYSCONFDIR=\"$(sysconfdir)/\" if BGPD -TESTS_BGPD = aspathtest testbgpcap ecommtest testbgpmpattr testbgpmpath -DEJATOOL += bgpd +TESTS_BGPD = \ + bgpd/test_aspath \ + bgpd/test_capability \ + bgpd/test_ecommunity \ + bgpd/test_mp_attr \ + bgpd/test_mpath else TESTS_BGPD = endif if ENABLE_BGP_VNC -BGP_VNC_RFP_LIB=@top_builddir@/$(LIBRFP)/librfp.a +BGP_VNC_RFP_LIB=@top_builddir@/$(LIBRFP)/librfp.a else BGP_VNC_RFP_LIB = endif -check_PROGRAMS = testsig testsegv testbuffer testmemory heavy heavywq heavythread \ - testprivs teststream testchecksum tabletest testnexthopiter \ - testcommands test-timer-correctness test-timer-performance \ - testcli \ - $(TESTS_BGPD) +check_PROGRAMS = \ + lib/test_buffer \ + lib/test_checksum \ + lib/test_heavy_thread \ + lib/test_heavy_wq \ + lib/test_heavy \ + lib/test_memory \ + lib/test_nexthop_iter \ + lib/test_privs \ + lib/test_segv \ + lib/test_sig \ + lib/test_stream \ + lib/test_table \ + lib/test_timer_correctness \ + lib/test_timer_performance \ + lib/cli/test_cli \ + lib/cli/test_commands \ + $(TESTS_BGPD) ../vtysh/vtysh_cmd.c: $(MAKE) -C ../vtysh vtysh_cmd.c -test-commands-defun.c: ../vtysh/vtysh_cmd.c +lib/cli/test_commands_defun.c: ../vtysh/vtysh_cmd.c sed \ -e 's/"vtysh\.h"/"tests.h"/' \ -e 's/vtysh_init_cmd/test_init_cmd/' \ -e 's/VTYSH_[A-Z][A-Z_0-9]*/0/g' \ < ../vtysh/vtysh_cmd.c \ - > test-commands-defun.c + > "$@" -BUILT_SOURCES = test-commands-defun.c -noinst_HEADERS = prng.h tests.h common-cli.h +BUILT_SOURCES = lib/cli/test_commands_defun.c -testcli_SOURCES = test-cli.c common-cli.c -testsig_SOURCES = test-sig.c -testsegv_SOURCES = test-segv.c -testbuffer_SOURCES = test-buffer.c -testmemory_SOURCES = test-memory.c -testprivs_SOURCES = test-privs.c -teststream_SOURCES = test-stream.c -heavy_SOURCES = heavy.c main.c -heavywq_SOURCES = heavy-wq.c main.c -heavythread_SOURCES = heavy-thread.c main.c -aspathtest_SOURCES = aspath_test.c -testbgpcap_SOURCES = bgp_capability_test.c -ecommtest_SOURCES = ecommunity_test.c -testbgpmpattr_SOURCES = bgp_mp_attr_test.c -testchecksum_SOURCES = test-checksum.c -testbgpmpath_SOURCES = bgp_mpath_test.c -tabletest_SOURCES = table_test.c -testnexthopiter_SOURCES = test-nexthop-iter.c prng.c -testcommands_SOURCES = test-commands-defun.c test-commands.c prng.c -test_timer_correctness_SOURCES = test-timer-correctness.c prng.c -test_timer_performance_SOURCES = test-timer-performance.c prng.c +noinst_HEADERS = \ + ./helpers/c/prng.h \ + ./helpers/c/tests.h \ + ./lib/cli/common_cli.h -testcli_LDADD = ../lib/libfrr.la @LIBCAP@ -testsig_LDADD = ../lib/libfrr.la @LIBCAP@ -testsegv_LDADD = ../lib/libfrr.la @LIBCAP@ -testbuffer_LDADD = ../lib/libfrr.la @LIBCAP@ -testmemory_LDADD = ../lib/libfrr.la @LIBCAP@ -testprivs_LDADD = ../lib/libfrr.la @LIBCAP@ -teststream_LDADD = ../lib/libfrr.la @LIBCAP@ -heavy_LDADD = ../lib/libfrr.la @LIBCAP@ -lm -heavywq_LDADD = ../lib/libfrr.la @LIBCAP@ -lm -heavythread_LDADD = ../lib/libfrr.la @LIBCAP@ -lm -aspathtest_LDADD = ../bgpd/libbgp.a $(BGP_VNC_RFP_LIB) ../lib/libfrr.la @LIBCAP@ -lm -testbgpcap_LDADD = ../bgpd/libbgp.a $(BGP_VNC_RFP_LIB) ../lib/libfrr.la @LIBCAP@ -lm -ecommtest_LDADD = ../bgpd/libbgp.a $(BGP_VNC_RFP_LIB) ../lib/libfrr.la @LIBCAP@ -lm -testbgpmpattr_LDADD = ../bgpd/libbgp.a $(BGP_VNC_RFP_LIB) ../lib/libfrr.la @LIBCAP@ -lm -testchecksum_LDADD = ../lib/libfrr.la @LIBCAP@ -testbgpmpath_LDADD = ../bgpd/libbgp.a $(BGP_VNC_RFP_LIB) ../lib/libfrr.la @LIBCAP@ -lm -tabletest_LDADD = ../lib/libfrr.la @LIBCAP@ -lm -testnexthopiter_LDADD = ../lib/libfrr.la @LIBCAP@ -testcommands_LDADD = ../lib/libfrr.la @LIBCAP@ -test_timer_correctness_LDADD = ../lib/libfrr.la @LIBCAP@ -test_timer_performance_LDADD = ../lib/libfrr.la @LIBCAP@ +lib_test_buffer_SOURCES = lib/test_buffer.c +lib_test_checksum_SOURCES = lib/test_checksum.c +lib_test_heavy_thread_SOURCES = lib/test_heavy_thread.c helpers/c/main.c +lib_test_heavy_wq_SOURCES = lib/test_heavy_wq.c helpers/c/main.c +lib_test_heavy_SOURCES = lib/test_heavy.c helpers/c/main.c +lib_test_memory_SOURCES = lib/test_memory.c +lib_test_nexthop_iter_SOURCES = lib/test_nexthop_iter.c helpers/c/prng.c +lib_test_privs_SOURCES = lib/test_privs.c +lib_test_segv_SOURCES = lib/test_segv.c +lib_test_sig_SOURCES = lib/test_sig.c +lib_test_stream_SOURCES = lib/test_stream.c +lib_test_table_SOURCES = lib/test_table.c +lib_test_timer_correctness_SOURCES = lib/test_timer_correctness.c \ + helpers/c/prng.c +lib_test_timer_performance_SOURCES = lib/test_timer_performance.c \ + helpers/c/prng.c +lib_cli_test_cli_SOURCES = lib/cli/test_cli.c lib/cli/common_cli.c +lib_cli_test_commands_SOURCES = lib/cli/test_commands_defun.c \ + lib/cli/test_commands.c \ + helpers/c/prng.c +bgpd_test_aspath_SOURCES = bgpd/test_aspath.c +bgpd_test_capability_SOURCES = bgpd/test_capability.c +bgpd_test_ecommunity_SOURCES = bgpd/test_ecommunity.c +bgpd_test_mp_attr_SOURCES = bgpd/test_mp_attr.c +bgpd_test_mpath_SOURCES = bgpd/test_mpath.c + +ALL_TESTS_LDADD = ../lib/libfrr.la @LIBCAP@ +BGP_TEST_LDADD = ../bgpd/libbgp.a $(BGP_VNC_RFP_LIB) $(ALL_TESTS_LDADD) -lm + +lib_test_buffer_LDADD = $(ALL_TESTS_LDADD) +lib_test_checksum_LDADD = $(ALL_TESTS_LDADD) +lib_test_heavy_thread_LDADD = $(ALL_TESTS_LDADD) -lm +lib_test_heavy_wq_LDADD = $(ALL_TESTS_LDADD) -lm +lib_test_heavy_LDADD = $(ALL_TESTS_LDADD) -lm +lib_test_memory_LDADD = $(ALL_TESTS_LDADD) +lib_test_nexthop_iter_LDADD = $(ALL_TESTS_LDADD) +lib_test_privs_LDADD = $(ALL_TESTS_LDADD) +lib_test_segv_LDADD = $(ALL_TESTS_LDADD) +lib_test_sig_LDADD = $(ALL_TESTS_LDADD) +lib_test_stream_LDADD = $(ALL_TESTS_LDADD) +lib_test_table_LDADD = $(ALL_TESTS_LDADD) -lm +lib_test_timer_correctness_LDADD = $(ALL_TESTS_LDADD) +lib_test_timer_performance_LDADD = $(ALL_TESTS_LDADD) +lib_cli_test_cli_LDADD = $(ALL_TESTS_LDADD) +lib_cli_test_commands_LDADD = $(ALL_TESTS_LDADD) +bgpd_test_aspath_LDADD = $(BGP_TEST_LDADD) +bgpd_test_capability_LDADD = $(BGP_TEST_LDADD) +bgpd_test_ecommunity_LDADD = $(BGP_TEST_LDADD) +bgpd_test_mp_attr_LDADD = $(BGP_TEST_LDADD) +bgpd_test_mpath_LDADD = $(BGP_TEST_LDADD) diff --git a/tests/aspath_test.c b/tests/bgpd/test_aspath.c similarity index 100% rename from tests/aspath_test.c rename to tests/bgpd/test_aspath.c diff --git a/tests/bgp_capability_test.c b/tests/bgpd/test_capability.c similarity index 100% rename from tests/bgp_capability_test.c rename to tests/bgpd/test_capability.c diff --git a/tests/ecommunity_test.c b/tests/bgpd/test_ecommunity.c similarity index 100% rename from tests/ecommunity_test.c rename to tests/bgpd/test_ecommunity.c diff --git a/tests/bgp_mp_attr_test.c b/tests/bgpd/test_mp_attr.c similarity index 100% rename from tests/bgp_mp_attr_test.c rename to tests/bgpd/test_mp_attr.c diff --git a/tests/bgp_mpath_test.c b/tests/bgpd/test_mpath.c similarity index 100% rename from tests/bgp_mpath_test.c rename to tests/bgpd/test_mpath.c diff --git a/tests/main.c b/tests/helpers/c/main.c similarity index 100% rename from tests/main.c rename to tests/helpers/c/main.c diff --git a/tests/prng.c b/tests/helpers/c/prng.c similarity index 100% rename from tests/prng.c rename to tests/helpers/c/prng.c diff --git a/tests/prng.h b/tests/helpers/c/prng.h similarity index 100% rename from tests/prng.h rename to tests/helpers/c/prng.h diff --git a/tests/tests.h b/tests/helpers/c/tests.h similarity index 100% rename from tests/tests.h rename to tests/helpers/c/tests.h diff --git a/tests/common-cli.c b/tests/lib/cli/common_cli.c similarity index 98% rename from tests/common-cli.c rename to tests/lib/cli/common_cli.c index aed20b2d53..ad9658f95f 100644 --- a/tests/common-cli.c +++ b/tests/lib/cli/common_cli.c @@ -29,7 +29,7 @@ #include "memory_vty.h" #include "log.h" -#include "common-cli.h" +#include "common_cli.h" struct thread_master *master; diff --git a/tests/common-cli.h b/tests/lib/cli/common_cli.h similarity index 100% rename from tests/common-cli.h rename to tests/lib/cli/common_cli.h diff --git a/tests/test-cli.c b/tests/lib/cli/test_cli.c similarity index 98% rename from tests/test-cli.c rename to tests/lib/cli/test_cli.c index 6fab6d52cb..978a431b6a 100644 --- a/tests/test-cli.c +++ b/tests/lib/cli/test_cli.c @@ -22,7 +22,7 @@ #include -#include "common-cli.h" +#include "common_cli.h" DUMMY_DEFUN(cmd0, "arg ipv4 A.B.C.D"); DUMMY_DEFUN(cmd1, "arg ipv4m A.B.C.D/M"); diff --git a/tests/testcli.in b/tests/lib/cli/test_cli.in similarity index 100% rename from tests/testcli.in rename to tests/lib/cli/test_cli.in diff --git a/tests/testcli.refout b/tests/lib/cli/test_cli.refout similarity index 100% rename from tests/testcli.refout rename to tests/lib/cli/test_cli.refout diff --git a/tests/test-commands.c b/tests/lib/cli/test_commands.c similarity index 100% rename from tests/test-commands.c rename to tests/lib/cli/test_commands.c diff --git a/tests/testcommands.in b/tests/lib/cli/test_commands.in similarity index 100% rename from tests/testcommands.in rename to tests/lib/cli/test_commands.in diff --git a/tests/testcommands.refout b/tests/lib/cli/test_commands.refout similarity index 100% rename from tests/testcommands.refout rename to tests/lib/cli/test_commands.refout diff --git a/tests/test-buffer.c b/tests/lib/test_buffer.c similarity index 100% rename from tests/test-buffer.c rename to tests/lib/test_buffer.c diff --git a/tests/test-checksum.c b/tests/lib/test_checksum.c similarity index 100% rename from tests/test-checksum.c rename to tests/lib/test_checksum.c diff --git a/tests/heavy.c b/tests/lib/test_heavy.c similarity index 100% rename from tests/heavy.c rename to tests/lib/test_heavy.c diff --git a/tests/heavy-thread.c b/tests/lib/test_heavy_thread.c similarity index 100% rename from tests/heavy-thread.c rename to tests/lib/test_heavy_thread.c diff --git a/tests/heavy-wq.c b/tests/lib/test_heavy_wq.c similarity index 100% rename from tests/heavy-wq.c rename to tests/lib/test_heavy_wq.c diff --git a/tests/test-memory.c b/tests/lib/test_memory.c similarity index 100% rename from tests/test-memory.c rename to tests/lib/test_memory.c diff --git a/tests/test-nexthop-iter.c b/tests/lib/test_nexthop_iter.c similarity index 100% rename from tests/test-nexthop-iter.c rename to tests/lib/test_nexthop_iter.c diff --git a/tests/test-privs.c b/tests/lib/test_privs.c similarity index 100% rename from tests/test-privs.c rename to tests/lib/test_privs.c diff --git a/tests/test-segv.c b/tests/lib/test_segv.c similarity index 100% rename from tests/test-segv.c rename to tests/lib/test_segv.c diff --git a/tests/test-sig.c b/tests/lib/test_sig.c similarity index 100% rename from tests/test-sig.c rename to tests/lib/test_sig.c diff --git a/tests/test-stream.c b/tests/lib/test_stream.c similarity index 100% rename from tests/test-stream.c rename to tests/lib/test_stream.c diff --git a/tests/lib/test_stream.refout b/tests/lib/test_stream.refout new file mode 100644 index 0000000000..cf52e1301e --- /dev/null +++ b/tests/lib/test_stream.refout @@ -0,0 +1,8 @@ +endp: 15, readable: 15, writeable: 1009 +0xef 0xbe 0xef 0xde 0xad 0xbe 0xef 0xde 0xad 0xbe 0xef 0xde 0xad 0xbe 0xef +endp: 15, readable: 15, writeable: 0 +0xef 0xbe 0xef 0xde 0xad 0xbe 0xef 0xde 0xad 0xbe 0xef 0xde 0xad 0xbe 0xef +c: 0xef +w: 0xbeef +l: 0xdeadbeef +q: 0xdeadbeefdeadbeef diff --git a/tests/table_test.c b/tests/lib/test_table.c similarity index 100% rename from tests/table_test.c rename to tests/lib/test_table.c diff --git a/tests/test-timer-correctness.c b/tests/lib/test_timer_correctness.c similarity index 100% rename from tests/test-timer-correctness.c rename to tests/lib/test_timer_correctness.c diff --git a/tests/test-timer-performance.c b/tests/lib/test_timer_performance.c similarity index 100% rename from tests/test-timer-performance.c rename to tests/lib/test_timer_performance.c From cbbf41cbb3cb8de05f21969dc497412c82573025 Mon Sep 17 00:00:00 2001 From: Christian Franke Date: Fri, 3 Feb 2017 16:58:58 +0100 Subject: [PATCH 08/27] tests: add pytest testrunners Signed-off-by: Christian Franke --- tests/.gitignore | 4 + tests/Makefile.am | 28 +++++ tests/bgpd/test_aspath.py | 79 +++++++++++++ tests/bgpd/test_capability.py | 47 ++++++++ tests/bgpd/test_ecommunity.py | 9 ++ tests/bgpd/test_mp_attr.py | 33 ++++++ tests/bgpd/test_mpath.py | 9 ++ tests/helpers/python/frrsix.py | 80 +++++++++++++ tests/helpers/python/frrtest.py | 177 ++++++++++++++++++++++++++++ tests/lib/cli/test_cli.py | 4 + tests/lib/cli/test_commands.py | 8 ++ tests/lib/test_nexthop_iter.py | 7 ++ tests/lib/test_stream.py | 4 + tests/lib/test_table.py | 10 ++ tests/lib/test_timer_correctness.py | 6 + tests/runtests.py | 6 + 16 files changed, 511 insertions(+) create mode 100644 tests/bgpd/test_aspath.py create mode 100644 tests/bgpd/test_capability.py create mode 100644 tests/bgpd/test_ecommunity.py create mode 100644 tests/bgpd/test_mp_attr.py create mode 100644 tests/bgpd/test_mpath.py create mode 100644 tests/helpers/python/frrsix.py create mode 100644 tests/helpers/python/frrtest.py create mode 100644 tests/lib/cli/test_cli.py create mode 100644 tests/lib/cli/test_commands.py create mode 100644 tests/lib/test_nexthop_iter.py create mode 100644 tests/lib/test_stream.py create mode 100644 tests/lib/test_table.py create mode 100644 tests/lib/test_timer_correctness.py create mode 100644 tests/runtests.py diff --git a/tests/.gitignore b/tests/.gitignore index 1642fa9493..bab3385da2 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -3,6 +3,7 @@ Makefile.in *.o tags TAGS +.cache .deps .nfs* *~ @@ -14,8 +15,11 @@ TAGS *.log *.sum *.xml +*.pyc .arch-inventory .arch-ids +__pycache__ +.dirstamp /bgpd/test_aspath /bgpd/test_capability /bgpd/test_ecommunity diff --git a/tests/Makefile.am b/tests/Makefile.am index 8b7ae57752..0d7e324fb1 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,3 +1,5 @@ +PYTHON ?= python + AUTOMAKE_OPTIONS = subdir-objects AM_CPPFLAGS = \ -I.. \ @@ -113,3 +115,29 @@ bgpd_test_capability_LDADD = $(BGP_TEST_LDADD) bgpd_test_ecommunity_LDADD = $(BGP_TEST_LDADD) bgpd_test_mp_attr_LDADD = $(BGP_TEST_LDADD) bgpd_test_mpath_LDADD = $(BGP_TEST_LDADD) + +EXTRA_DIST = \ + runtests.py \ + bgpd/test_aspath.py \ + bgpd/test_capability.py \ + bgpd/test_ecommunity.py \ + bgpd/test_mp_attr.py \ + bgpd/test_mpath.py \ + helpers/python/frrsix.py \ + helpers/python/frrtest.py \ + lib/cli/test_commands.in \ + lib/cli/test_commands.py \ + lib/cli/test_commands.refout \ + lib/cli/test_cli.in \ + lib/cli/test_cli.py \ + lib/cli/test_cli.refout \ + lib/test_nexthop_iter.py \ + lib/test_stream.py \ + lib/test_stream.refout \ + lib/test_table.py \ + lib/test_timer_correctness.py + +.PHONY: tests.xml +tests.xml: $(check_PROGRAMS) + $(PYTHON) runtests.py --junitxml=$@ -v +check: tests.xml diff --git a/tests/bgpd/test_aspath.py b/tests/bgpd/test_aspath.py new file mode 100644 index 0000000000..15ae514c87 --- /dev/null +++ b/tests/bgpd/test_aspath.py @@ -0,0 +1,79 @@ +import frrtest +import re + +re_okfail = re.compile(r'^(?:\x1b\[3[12]m)?(?POK|failed)'.encode('utf8'), + re.MULTILINE) + +class TestAspath(frrtest.TestMultiOut): + program = './test_aspath' + + def _parsertest(self, line): + if not hasattr(self, 'parserno'): + self.parserno = -1 + self.parserno += 1 + + self._onesimple("test %d" % self.parserno) + self._okfail("%s:" % line, okfail=re_okfail) + self._okfail("empty prepend %s:" % line, okfail=re_okfail) + + def _attrtest(self, line): + if not hasattr(self, 'attrno'): + self.attrno = -1 + self.attrno += 1 + + self._onesimple("aspath_attr test %d" % self.attrno) + self._okfail(line, okfail=re_okfail) + +TestAspath.parsertest("seq1") +TestAspath.parsertest("seq2") +TestAspath.parsertest("seq3") +TestAspath.parsertest("seqset") +TestAspath.parsertest("seqset2") +TestAspath.parsertest("multi") +TestAspath.parsertest("confed") +TestAspath.parsertest("confed2") +TestAspath.parsertest("confset") +TestAspath.parsertest("confmulti") +TestAspath.parsertest("seq4") +TestAspath.parsertest("tripleseq1") +TestAspath.parsertest("someprivate") +TestAspath.parsertest("allprivate") +TestAspath.parsertest("long") +TestAspath.parsertest("seq1extra") +TestAspath.parsertest("empty") +TestAspath.parsertest("redundantset") +TestAspath.parsertest("reconcile_lead_asp") +TestAspath.parsertest("reconcile_new_asp") +TestAspath.parsertest("reconcile_confed") +TestAspath.parsertest("reconcile_start_trans") +TestAspath.parsertest("reconcile_start_trans4") +TestAspath.parsertest("reconcile_start_trans_error") +TestAspath.parsertest("redundantset2") +TestAspath.parsertest("zero-size overflow") +TestAspath.parsertest("zero-size overflow + valid segment") +TestAspath.parsertest("invalid segment type") + +for i in range(10): + TestAspath.okfail("prepend test %d" % i) +for i in range(5): + TestAspath.okfail("aggregate test %d" % i) +for i in range(5): + TestAspath.okfail("reconcile test %d" % i) +for _ in range(22): + TestAspath.okfail("left cmp ") + +TestAspath.okfail("empty_get_test") + +TestAspath.attrtest("basic test") +TestAspath.attrtest("length too short") +TestAspath.attrtest("length too long") +TestAspath.attrtest("incorrect flag") +TestAspath.attrtest("as4_path, with as2 format data") +TestAspath.attrtest("as4, with incorrect attr length") +TestAspath.attrtest("basic 4-byte as-path") +TestAspath.attrtest("4b AS_PATH: too short") +TestAspath.attrtest("4b AS_PATH: too long") +TestAspath.attrtest("4b AS_PATH: too long2") +TestAspath.attrtest("4b AS_PATH: bad flags") +TestAspath.attrtest("4b AS4_PATH w/o AS_PATH") +TestAspath.attrtest("4b AS4_PATH: confed") diff --git a/tests/bgpd/test_capability.py b/tests/bgpd/test_capability.py new file mode 100644 index 0000000000..4cb650092b --- /dev/null +++ b/tests/bgpd/test_capability.py @@ -0,0 +1,47 @@ +import frrtest + +class TestCapability(frrtest.TestMultiOut): + program = './test_capability' + +TestCapability.okfail("MP4: MP IP/Uni") +TestCapability.okfail("MPv6: MP IPv6/Uni") +TestCapability.okfail("MP2: MP IP/Multicast") +TestCapability.okfail("MP3: MP IP6/MPLS-labeled VPN") +TestCapability.okfail("MP5: MP IP6/MPLS-VPN") +TestCapability.okfail("MP6: MP IP4/MPLS-laveled VPN") +TestCapability.okfail("MP8: MP unknown AFI/SAFI") +TestCapability.okfail("MP-short: MP IP4/Unicast, length too short (< minimum)") +TestCapability.okfail("MP-overflow: MP IP4/Unicast, length too long") +TestCapability.okfail("caphdr: capability header, and no more") +TestCapability.okfail("nodata: header, no data but length says there is") +TestCapability.okfail("padded: valid, with padding") +TestCapability.okfail("minsize: violates minsize requirement") +TestCapability.okfail("ORF: ORF, simple, single entry, single tuple") +TestCapability.okfail("ORF-many: ORF, multi entry/tuple") +TestCapability.okfail("ORFlo: ORF, multi entry/tuple, hdr length too short") +TestCapability.okfail("ORFlu: ORF, multi entry/tuple, length too long") +TestCapability.okfail("ORFnu: ORF, multi entry/tuple, entry number too long") +TestCapability.okfail("ORFno: ORF, multi entry/tuple, entry number too short") +TestCapability.okfail("ORFpad: ORF, multi entry/tuple, padded to align") +TestCapability.okfail("AS4: AS4 capability") +TestCapability.okfail("GR: GR capability") +TestCapability.okfail("GR-short: GR capability, but header length too short") +TestCapability.okfail("GR-long: GR capability, but header length too long") +TestCapability.okfail("GR-trunc: GR capability, but truncated") +TestCapability.okfail("GR-empty: GR capability, but empty.") +TestCapability.okfail("MP-empty: MP capability, but empty.") +TestCapability.okfail("ORF-empty: ORF capability, but empty.") +TestCapability.okfail("AS4-empty: AS4 capability, but empty.") +TestCapability.okfail("dyn-empty: Dynamic capability, but empty.") +TestCapability.okfail("dyn-old: Dynamic capability (deprecated version)") +TestCapability.okfail("Cap-singlets: One capability per Optional-Param") +TestCapability.okfail("Cap-series: Series of capability, one Optional-Param") +TestCapability.okfail("AS4more: AS4 capability after other caps (singlets)") +TestCapability.okfail("AS4series: AS4 capability, in series of capabilities") +TestCapability.okfail("AS4real: AS4 capability, in series of capabilities") +TestCapability.okfail("AS4real2: AS4 capability, in series of capabilities") +TestCapability.okfail("DynCap: Dynamic Capability Message, IP/Multicast") +TestCapability.okfail("DynCapLong: Dynamic Capability Message, IP/Multicast, truncated") +TestCapability.okfail("DynCapPadded: Dynamic Capability Message, IP/Multicast, padded") +TestCapability.okfail("DynCapMPCpadded: Dynamic Capability Message, IP/Multicast, cap data padded") +TestCapability.okfail("DynCapMPCoverflow: Dynamic Capability Message, IP/Multicast, cap data != length") diff --git a/tests/bgpd/test_ecommunity.py b/tests/bgpd/test_ecommunity.py new file mode 100644 index 0000000000..3a17ec9e31 --- /dev/null +++ b/tests/bgpd/test_ecommunity.py @@ -0,0 +1,9 @@ +import frrtest + +class TestEcommunity(frrtest.TestMultiOut): + program = './test_ecommunity' + +TestEcommunity.okfail('ipaddr') +TestEcommunity.okfail('ipaddr-so') +TestEcommunity.okfail('asn') +TestEcommunity.okfail('asn4') diff --git a/tests/bgpd/test_mp_attr.py b/tests/bgpd/test_mp_attr.py new file mode 100644 index 0000000000..46d0c42402 --- /dev/null +++ b/tests/bgpd/test_mp_attr.py @@ -0,0 +1,33 @@ +import frrtest + +class TestMpAttr(frrtest.TestMultiOut): + program = './test_mp_attr' + +TestMpAttr.okfail("IPv6: IPV6 MP Reach, global nexthop, 1 NLRI") +TestMpAttr.okfail("IPv6-2: IPV6 MP Reach, global nexthop, 2 NLRIs") +TestMpAttr.okfail("IPv6-default: IPV6 MP Reach, global nexthop, 2 NLRIs + default") +TestMpAttr.okfail("IPv6-lnh: IPV6 MP Reach, global+local nexthops, 2 NLRIs + default") +TestMpAttr.okfail("IPv6-nhlen: IPV6 MP Reach, inappropriate nexthop length") +TestMpAttr.okfail("IPv6-nhlen2: IPV6 MP Reach, invalid nexthop length") +TestMpAttr.okfail("IPv6-nhlen3: IPV6 MP Reach, nexthop length overflow") +TestMpAttr.okfail("IPv6-nhlen4: IPV6 MP Reach, nexthop length short") +TestMpAttr.okfail("IPv6-nlri: IPV6 MP Reach, NLRI bitlen overflow") +TestMpAttr.okfail("IPv4: IPv4 MP Reach, 2 NLRIs + default") +TestMpAttr.okfail("IPv4-nhlen: IPv4 MP Reach, nexthop lenth overflow") +TestMpAttr.okfail("IPv4-nlrilen: IPv4 MP Reach, nlri lenth overflow") +TestMpAttr.okfail("IPv4-VPNv4: IPv4/VPNv4 MP Reach, RD, Nexthop, 2 NLRIs") +TestMpAttr.okfail("IPv4-VPNv4-bogus-plen: IPv4/MPLS-labeled VPN MP Reach, RD, Nexthop, NLRI / bogus p'len") +TestMpAttr.okfail("IPv4-VPNv4-plen1-short: IPv4/VPNv4 MP Reach, RD, Nexthop, 2 NLRIs, 1st plen short") +TestMpAttr.okfail("IPv4-VPNv4-plen1-long: IPv4/VPNv4 MP Reach, RD, Nexthop, 2 NLRIs, 1st plen long") +TestMpAttr.okfail("IPv4-VPNv4-plenn-long: IPv4/VPNv4 MP Reach, RD, Nexthop, 3 NLRIs, last plen long") +TestMpAttr.okfail("IPv4-VPNv4-plenn-short: IPv4/VPNv4 MP Reach, RD, Nexthop, 2 NLRIs, last plen short") +TestMpAttr.okfail("IPv4-VPNv4-bogus-rd-type: IPv4/VPNv4 MP Reach, RD, NH, 2 NLRI, unknown RD in 1st (log, but parse)") +TestMpAttr.okfail("IPv4-VPNv4-0-nlri: IPv4/VPNv4 MP Reach, RD, Nexthop, 3 NLRI, 3rd 0 bogus") +TestMpAttr.okfail("IPv6-bug: IPv6, global nexthop, 1 default NLRI") +TestMpAttr.okfail("IPv6-unreach: IPV6 MP Unreach, 1 NLRI") +TestMpAttr.okfail("IPv6-unreach2: IPV6 MP Unreach, 2 NLRIs") +TestMpAttr.okfail("IPv6-unreach-default: IPV6 MP Unreach, 2 NLRIs + default") +TestMpAttr.okfail("IPv6-unreach-nlri: IPV6 MP Unreach, NLRI bitlen overflow") +TestMpAttr.okfail("IPv4-unreach: IPv4 MP Unreach, 2 NLRIs + default") +TestMpAttr.okfail("IPv4-unreach-nlrilen: IPv4 MP Unreach, nlri length overflow") +TestMpAttr.okfail("IPv4-unreach-VPNv4: IPv4/MPLS-labeled VPN MP Unreach, RD, 3 NLRIs") diff --git a/tests/bgpd/test_mpath.py b/tests/bgpd/test_mpath.py new file mode 100644 index 0000000000..3024669507 --- /dev/null +++ b/tests/bgpd/test_mpath.py @@ -0,0 +1,9 @@ +import frrtest + +class TestMpath(frrtest.TestMultiOut): + program = './test_mpath' + +TestMpath.okfail("bgp maximum-paths config") +TestMpath.okfail("bgp_mp_list") +TestMpath.okfail("bgp_info_mpath_update") + diff --git a/tests/helpers/python/frrsix.py b/tests/helpers/python/frrsix.py new file mode 100644 index 0000000000..91714f0c67 --- /dev/null +++ b/tests/helpers/python/frrsix.py @@ -0,0 +1,80 @@ +# +# Copyright (c) 2010-2017 Benjamin Peterson +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +# + +# +# This code is taken from the six python2 to python3 compatibility module +# + +import sys + +PY2 = sys.version_info[0] == 2 +PY3 = sys.version_info[0] == 3 + +def add_metaclass(metaclass): + """Class decorator for creating a class with a metaclass.""" + def wrapper(cls): + orig_vars = cls.__dict__.copy() + slots = orig_vars.get('__slots__') + if slots is not None: + if isinstance(slots, str): + slots = [slots] + for slots_var in slots: + orig_vars.pop(slots_var) + orig_vars.pop('__dict__', None) + orig_vars.pop('__weakref__', None) + return metaclass(cls.__name__, cls.__bases__, orig_vars) + return wrapper + +if PY3: + import builtins + exec_ = getattr(builtins,'exec') + + def reraise(tp, value, tb=None): + try: + if value is None: + value = tp() + if value.__traceback__ is not tb: + raise value.with_traceback(tb) + raise value + finally: + value = None + tb = None + +else: + def exec_(_code_, _globs_=None, _locs_=None): + """Execute code in a namespace.""" + if _globs_ is None: + frame = sys._getframe(1) + _globs_ = frame.f_globals + if _locs_ is None: + _locs_ = frame.f_locals + del frame + elif _locs_ is None: + _locs_ = _globs_ + exec("""exec _code_ in _globs_, _locs_""") + + exec_("""def reraise(tp, value, tb=None): + try: + raise tp, value, tb + finally: + tb = None +""") diff --git a/tests/helpers/python/frrtest.py b/tests/helpers/python/frrtest.py new file mode 100644 index 0000000000..2814416d11 --- /dev/null +++ b/tests/helpers/python/frrtest.py @@ -0,0 +1,177 @@ +# +# Test helpers for FRR +# +# Copyright (C) 2017 by David Lamparter & Christian Franke, +# Open Source Routing / NetDEF Inc. +# +# This file is part of FreeRangeRouting (FRR) +# +# FRR 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, or (at your option) any +# later version. +# +# FRR 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 FRR; see the file COPYING. If not, write to the Free +# Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA +# 02111-1307, USA. +# + +import subprocess +import sys +import re +import inspect +import os + +import frrsix + +# +# These are the gritty internals of the TestMultiOut implementation. +# See below for the definition of actual TestMultiOut tests. +# + +class MultiTestFailure(Exception): + pass + +class MetaTestMultiOut(type): + def __getattr__(cls, name): + if name.startswith('_'): + raise AttributeError + + internal_name = '_{}'.format(name) + if internal_name not in dir(cls): + raise AttributeError + + def registrar(*args, **kwargs): + cls._add_test(getattr(cls,internal_name), *args, **kwargs) + return registrar + +@frrsix.add_metaclass(MetaTestMultiOut) +class _TestMultiOut(object): + def _run_tests(self): + if 'tests_run' in dir(self.__class__) and self.tests_run: + return + self.__class__.tests_run = True + basedir = os.path.dirname(inspect.getsourcefile(type(self))) + program = os.path.join(basedir, self.program) + proc = subprocess.Popen([program], stdout=subprocess.PIPE) + self.output,_ = proc.communicate('') + self.exitcode = proc.wait() + + self.__class__.testresults = {} + for test in self.tests: + try: + test(self) + except MultiTestFailure: + self.testresults[test] = sys.exc_info() + else: + self.testresults[test] = None + + def _exit_cleanly(self): + if self.exitcode != 0: + raise MultiTestFailure("Program did not terminate with exit code 0") + + @classmethod + def _add_test(cls, method, *args, **kwargs): + if 'tests' not in dir(cls): + setattr(cls,'tests',[]) + cls._add_test(cls._exit_cleanly) + + def matchfunction(self): + method(self, *args, **kwargs) + cls.tests.append(matchfunction) + + def testfunction(self): + self._run_tests() + result = self.testresults[matchfunction] + if result is not None: + frrsix.reraise(*result) + + testname = re.sub(r'[^A-Za-z0-9]', '_', '%r%r' % (args, kwargs)) + testname = re.sub(r'__*', '_', testname) + testname = testname.strip('_') + if not testname: + testname = method.__name__.strip('_') + if "test_%s" % testname in dir(cls): + index = 2 + while "test_%s_%d" % (testname,index) in dir(cls): + index += 1 + testname = "%s_%d" % (testname, index) + setattr(cls,"test_%s" % testname, testfunction) + +# +# This class houses the actual TestMultiOut tests types. +# If you want to add a new test type, you probably do it here. +# +# Say you want to add a test type called foobarlicious. Then define +# a function _foobarlicious here that takes self and the test arguments +# when called. That function should check the output in self.output +# to see whether it matches the expectation of foobarlicious with the +# given arguments and should then adjust self.output according to how +# much output it consumed. +# If the output doesn't meet the expectations, MultiTestFailure can be +# raised, however that should only be done after self.output has been +# modified according to consumed content. +# + +re_okfail = re.compile(r'(?:[3[12]m|^)?(?POK|failed)'.encode('utf8'), + re.MULTILINE) +class TestMultiOut(_TestMultiOut): + def _onesimple(self, line): + if type(line) is str: + line = line.encode('utf8') + idx = self.output.find(line) + if idx != -1: + self.output = self.output[idx+len(line):] + else: + raise MultiTestFailure("%r could not be found" % line) + + def _okfail(self, line, okfail=re_okfail): + self._onesimple(line) + + m = okfail.search(self.output) + if m is None: + raise MultiTestFailure('OK/fail not found') + self.output = self.output[m.end():] + + if m.group('ret') != 'OK'.encode('utf8'): + raise MultiTestFailure('Test output indicates failure') + +# +# This class implements a test comparing the output of a program against +# an existing reference output +# + +class TestRefMismatch(Exception): + pass +class TestExitNonzero(Exception): + pass + +class TestRefOut(object): + def test_refout(self): + basedir = os.path.dirname(inspect.getsourcefile(type(self))) + program = os.path.join(basedir, self.program) + + refin = program + '.in' + refout = program + '.refout' + + intext = '' + if os.path.exists(refin): + with open(refin, 'rb') as f: + intext = f.read() + with open(refout, 'rb') as f: + reftext = f.read() + + proc = subprocess.Popen([program], + stdin=subprocess.PIPE, + stdout=subprocess.PIPE) + outtext,_ = proc.communicate(intext) + if outtext != reftext: + raise TestRefMismatch(self, outtext, reftext) + if proc.wait() != 0: + raise TestExitNonzero(self) diff --git a/tests/lib/cli/test_cli.py b/tests/lib/cli/test_cli.py new file mode 100644 index 0000000000..e3c31c2d91 --- /dev/null +++ b/tests/lib/cli/test_cli.py @@ -0,0 +1,4 @@ +import frrtest + +class TestCli(frrtest.TestRefOut): + program = './test_cli' diff --git a/tests/lib/cli/test_commands.py b/tests/lib/cli/test_commands.py new file mode 100644 index 0000000000..85e34fa15b --- /dev/null +++ b/tests/lib/cli/test_commands.py @@ -0,0 +1,8 @@ +import frrtest +import pytest +import os + +@pytest.mark.skipif('QUAGGA_TEST_COMMANDS' not in os.environ, + reason='QUAGGA_TEST_COMMANDS not set') +class TestCommands(frrtest.TestRefOut): + program = './test_commands' diff --git a/tests/lib/test_nexthop_iter.py b/tests/lib/test_nexthop_iter.py new file mode 100644 index 0000000000..bb330a1c75 --- /dev/null +++ b/tests/lib/test_nexthop_iter.py @@ -0,0 +1,7 @@ +import frrtest + +class TestNexthopIter(frrtest.TestMultiOut): + program = './test_nexthop_iter' + +TestNexthopIter.onesimple('Simple test passed.') +TestNexthopIter.onesimple('PRNG test passed.') diff --git a/tests/lib/test_stream.py b/tests/lib/test_stream.py new file mode 100644 index 0000000000..6f42db1839 --- /dev/null +++ b/tests/lib/test_stream.py @@ -0,0 +1,4 @@ +import frrtest + +class TestStream(frrtest.TestRefOut): + program = './test_stream' diff --git a/tests/lib/test_table.py b/tests/lib/test_table.py new file mode 100644 index 0000000000..e724421273 --- /dev/null +++ b/tests/lib/test_table.py @@ -0,0 +1,10 @@ +import frrtest + +class TestTable(frrtest.TestMultiOut): + program = './test_table' + +for i in range(6): + TestTable.onesimple('Verifying cmp') +for i in range(11): + TestTable.onesimple('Verifying successor') +TestTable.onesimple('Verified pausing') diff --git a/tests/lib/test_timer_correctness.py b/tests/lib/test_timer_correctness.py new file mode 100644 index 0000000000..8b4a765a81 --- /dev/null +++ b/tests/lib/test_timer_correctness.py @@ -0,0 +1,6 @@ +import frrtest + +class TestTimerCorrectness(frrtest.TestMultiOut): + program = './test_timer_correctness' + +TestTimerCorrectness.onesimple('Expected output and actual output match.') diff --git a/tests/runtests.py b/tests/runtests.py new file mode 100644 index 0000000000..533dc6b167 --- /dev/null +++ b/tests/runtests.py @@ -0,0 +1,6 @@ +import pytest +import sys +import os + +sys.path.append(os.path.join(os.path.dirname(__file__), 'helpers','python')) +raise SystemExit(pytest.main(sys.argv[1:])) From 43dac2baaef0d7061befe8c98f708b108c4ae2c9 Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Sat, 11 Feb 2017 01:03:57 +0100 Subject: [PATCH 09/27] tests: fix out-of-tree build Fix pytest with $(top_srcdir) != "." Signed-off-by: David Lamparter --- tests/Makefile.am | 2 +- tests/helpers/python/frrtest.py | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/tests/Makefile.am b/tests/Makefile.am index 0d7e324fb1..e825090e16 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -139,5 +139,5 @@ EXTRA_DIST = \ .PHONY: tests.xml tests.xml: $(check_PROGRAMS) - $(PYTHON) runtests.py --junitxml=$@ -v + $(PYTHON) $(srcdir)/runtests.py --junitxml=$@ -v $(srcdir) check: tests.xml diff --git a/tests/helpers/python/frrtest.py b/tests/helpers/python/frrtest.py index 2814416d11..20c854f66c 100644 --- a/tests/helpers/python/frrtest.py +++ b/tests/helpers/python/frrtest.py @@ -35,6 +35,12 @@ import frrsix # See below for the definition of actual TestMultiOut tests. # +srcbase = os.path.abspath(inspect.getsourcefile(frrsix)) +for i in range(0, 3): + srcbase = os.path.dirname(srcbase) +def binpath(srcpath): + return os.path.relpath(os.path.abspath(srcpath), srcbase) + class MultiTestFailure(Exception): pass @@ -59,7 +65,7 @@ class _TestMultiOut(object): self.__class__.tests_run = True basedir = os.path.dirname(inspect.getsourcefile(type(self))) program = os.path.join(basedir, self.program) - proc = subprocess.Popen([program], stdout=subprocess.PIPE) + proc = subprocess.Popen([binpath(program)], stdout=subprocess.PIPE) self.output,_ = proc.communicate('') self.exitcode = proc.wait() @@ -167,7 +173,7 @@ class TestRefOut(object): with open(refout, 'rb') as f: reftext = f.read() - proc = subprocess.Popen([program], + proc = subprocess.Popen([binpath(program)], stdin=subprocess.PIPE, stdout=subprocess.PIPE) outtext,_ = proc.communicate(intext) From f75352362c0c2f0142d54c88f5ab03afb84f6ef1 Mon Sep 17 00:00:00 2001 From: Christian Franke Date: Mon, 13 Feb 2017 19:27:54 +0100 Subject: [PATCH 10/27] isisd: address coverity findings --- isisd/dict.c | 1 + isisd/isis_circuit.c | 4 ++-- isisd/isis_lsp.c | 3 +-- isisd/isis_pdu.c | 4 ++-- isisd/isis_route.c | 10 ++++++---- isisd/isis_te.c | 17 ++++++----------- 6 files changed, 18 insertions(+), 21 deletions(-) diff --git a/isisd/dict.c b/isisd/dict.c index a038028d22..56676edaf1 100644 --- a/isisd/dict.c +++ b/isisd/dict.c @@ -649,6 +649,7 @@ dnode_t *dict_delete(dict_t *dict, dnode_t *delete) if (delete->left != nil && delete->right != nil) { dnode_t *next = dict_next(dict, delete); + assert (next); dnode_t *nextparent = next->parent; dnode_color_t nextcolor = next->color; diff --git a/isisd/isis_circuit.c b/isisd/isis_circuit.c index 0ea6c3d453..3a89766b2f 100644 --- a/isisd/isis_circuit.c +++ b/isisd/isis_circuit.c @@ -308,12 +308,12 @@ isis_circuit_del_addr (struct isis_circuit *circuit, else { prefix2str (connected->address, buf, sizeof (buf)); - zlog_warn ("Nonexitant ip address %s removal attempt from \ + zlog_warn ("Nonexistant ip address %s removal attempt from \ circuit %d", buf, circuit->circuit_id); zlog_warn ("Current ip addresses on %s:", circuit->interface->name); for (ALL_LIST_ELEMENTS_RO(circuit->ip_addrs, node, ip)) { - prefix2str((struct prefix*)ip, (char *)buf, BUFSIZ); + prefix2str(ip, buf, sizeof(buf)); zlog_warn(" %s", buf); } zlog_warn("End of addresses"); diff --git a/isisd/isis_lsp.c b/isisd/isis_lsp.c index c13bcc5d8a..a710c00e5f 100644 --- a/isisd/isis_lsp.c +++ b/isisd/isis_lsp.c @@ -2484,8 +2484,7 @@ lsp_regenerate_schedule_pseudo (struct isis_circuit *circuit, int level) int lvl; struct isis_area *area = circuit->area; - if (circuit == NULL || - circuit->circ_type != CIRCUIT_T_BROADCAST || + if (circuit->circ_type != CIRCUIT_T_BROADCAST || circuit->state != C_STATE_UP) return ISIS_OK; diff --git a/isisd/isis_pdu.c b/isisd/isis_pdu.c index 96e459a797..114c05bec0 100644 --- a/isisd/isis_pdu.c +++ b/isisd/isis_pdu.c @@ -2430,7 +2430,7 @@ send_lan_l1_hello (struct thread *thread) } if (circuit->u.bc.run_dr_elect[0]) - retval = isis_dr_elect (circuit, 1); + isis_dr_elect (circuit, 1); retval = send_hello (circuit, 1); @@ -2460,7 +2460,7 @@ send_lan_l2_hello (struct thread *thread) } if (circuit->u.bc.run_dr_elect[1]) - retval = isis_dr_elect (circuit, 2); + isis_dr_elect (circuit, 2); retval = send_hello (circuit, 2); diff --git a/isisd/isis_route.c b/isisd/isis_route.c index cc3ecba0d3..101d40dba3 100644 --- a/isisd/isis_route.c +++ b/isisd/isis_route.c @@ -585,10 +585,14 @@ isis_route_validate_merge (struct isis_area *area, int family) if (family == AF_INET) table = area->route_table[0]; -#ifdef HAVE_IPV6 else if (family == AF_INET6) table = area->route_table6[0]; -#endif + else + { + zlog_warn ("ISIS-Rte (%s) %s called for unknown family %d", + area->area_tag, __func__, family); + return; + } for (rnode = route_top (table); rnode; rnode = route_next (rnode)) { @@ -600,10 +604,8 @@ isis_route_validate_merge (struct isis_area *area, int family) if (family == AF_INET) table = area->route_table[1]; -#ifdef HAVE_IPV6 else if (family == AF_INET6) table = area->route_table6[1]; -#endif for (rnode = route_top (table); rnode; rnode = route_next (rnode)) { diff --git a/isisd/isis_te.c b/isisd/isis_te.c index ecbb63c92b..51919bb3f2 100644 --- a/isisd/isis_te.c +++ b/isisd/isis_te.c @@ -985,17 +985,15 @@ show_vty_unknown_tlv (struct vty *vty, struct subtlv_header *tlvh) void mpls_te_print_detail(struct vty *vty, struct te_is_neigh *te) { - struct subtlv_header *tlvh, *next; + struct subtlv_header *tlvh; u_int16_t sum = 0; zlog_debug ("ISIS MPLS-TE: Show database TE detail"); tlvh = (struct subtlv_header *)te->sub_tlvs; - for (; sum < te->sub_tlvs_length; tlvh = (next ? next : SUBTLV_HDR_NEXT (tlvh))) + for (; sum < te->sub_tlvs_length; tlvh = SUBTLV_HDR_NEXT (tlvh)) { - next = NULL; - switch (tlvh->type) { case TE_SUBTLV_ADMIN_GRP: @@ -1222,13 +1220,10 @@ DEFUN (show_isis_mpls_te_router, { vty_out (vty, "--- MPLS-TE router parameters ---%s", VTY_NEWLINE); - if (vty != NULL) - { - if (ntohs (isisMplsTE.router_id.s_addr) != 0) - vty_out (vty, " Router-Address: %s%s", inet_ntoa (isisMplsTE.router_id), VTY_NEWLINE); - else - vty_out (vty, " N/A%s", VTY_NEWLINE); - } + if (ntohs (isisMplsTE.router_id.s_addr) != 0) + vty_out (vty, " Router-Address: %s%s", inet_ntoa (isisMplsTE.router_id), VTY_NEWLINE); + else + vty_out (vty, " N/A%s", VTY_NEWLINE); } else vty_out (vty, " MPLS-TE is disable on this router%s", VTY_NEWLINE); From 29d63778fcd8dc3c2681584ddb12b6a44f05f95e Mon Sep 17 00:00:00 2001 From: Christian Franke Date: Mon, 13 Feb 2017 19:31:09 +0100 Subject: [PATCH 11/27] *: Add missing files to gitignore --- ospfd/.gitignore | 2 +- redhat/.gitignore | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ospfd/.gitignore b/ospfd/.gitignore index f7d6f09f22..4b8787c89e 100644 --- a/ospfd/.gitignore +++ b/ospfd/.gitignore @@ -14,4 +14,4 @@ TAGS .arch-ids *~ *.loT - +*.a diff --git a/redhat/.gitignore b/redhat/.gitignore index e399bd8114..a38f1c06e3 100644 --- a/redhat/.gitignore +++ b/redhat/.gitignore @@ -1,5 +1,5 @@ zebra.spec -quagga.spec +frr.spec Makefile Makefile.in .nfs* From 9b127e580474f6a075046f81d3228d3ed29421b3 Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Sat, 3 Dec 2016 21:14:44 -0200 Subject: [PATCH 12/27] ldpd: use red-black trees to store 'lde_map' elements Using red-black trees instead of linked lists brings the following benefits: 1 - Elements are naturally ordered (no need to reorder anything before outputting data to the user); 2 - Faster lookups/deletes: O(log n) time complexity against O(n). The insert operation with red-black trees is more expensive though, but that's not a big issue since lookups are much more frequent. Signed-off-by: Renato Westphal --- ldpd/l2vpn.c | 4 ++-- ldpd/lde.c | 17 ++++++++++++++--- ldpd/lde.h | 9 ++++++--- ldpd/lde_lib.c | 18 +++++++++--------- 4 files changed, 31 insertions(+), 17 deletions(-) diff --git a/ldpd/l2vpn.c b/ldpd/l2vpn.c index db382e484f..3159d47dd8 100644 --- a/ldpd/l2vpn.c +++ b/ldpd/l2vpn.c @@ -459,7 +459,7 @@ l2vpn_binding_ctl(pid_t pid) fn = (struct fec_node *)f; if (fn->local_label == NO_LABEL && - LIST_EMPTY(&fn->downstream)) + RB_EMPTY(&fn->downstream)) continue; memset(&pwctl, 0, sizeof(pwctl)); @@ -477,7 +477,7 @@ l2vpn_binding_ctl(pid_t pid) } else pwctl.local_label = NO_LABEL; - LIST_FOREACH(me, &fn->downstream, entry) + RB_FOREACH(me, lde_map_head, &fn->downstream) if (f->u.pwid.lsr_id.s_addr == me->nexthop->id.s_addr) break; diff --git a/ldpd/lde.c b/ldpd/lde.c index 29c9590908..47bb326258 100644 --- a/ldpd/lde.c +++ b/ldpd/lde.c @@ -45,12 +45,14 @@ static struct lde_nbr *lde_nbr_find(uint32_t); static void lde_nbr_clear(void); static void lde_nbr_addr_update(struct lde_nbr *, struct lde_addr *, int); +static __inline int lde_map_compare(struct lde_map *, struct lde_map *); static void lde_map_free(void *); static int lde_address_add(struct lde_nbr *, struct lde_addr *); static int lde_address_del(struct lde_nbr *, struct lde_addr *); static void lde_address_list_free(struct lde_nbr *); RB_GENERATE(nbr_tree, lde_nbr, entry, lde_nbr_compare) +RB_GENERATE(lde_map_head, lde_map, entry, lde_map_compare) struct ldpd_conf *ldeconf; struct nbr_tree lde_nbrs = RB_INITIALIZER(&lde_nbrs); @@ -1136,6 +1138,13 @@ lde_nbr_addr_update(struct lde_nbr *ln, struct lde_addr *lde_addr, int removed) } } +static __inline int +lde_map_compare(struct lde_map *a, struct lde_map *b) +{ + return (ldp_addrcmp(AF_INET, (union ldpd_addr *)&a->nexthop->id, + (union ldpd_addr *)&b->nexthop->id)); +} + struct lde_map * lde_map_add(struct lde_nbr *ln, struct fec_node *fn, int sent) { @@ -1149,13 +1158,15 @@ lde_map_add(struct lde_nbr *ln, struct fec_node *fn, int sent) me->nexthop = ln; if (sent) { - LIST_INSERT_HEAD(&fn->upstream, me, entry); + RB_INSERT(lde_map_head, &fn->upstream, me); + me->head = &fn->upstream; if (fec_insert(&ln->sent_map, &me->fec)) log_warnx("failed to add %s to sent map", log_fec(&me->fec)); /* XXX on failure more cleanup is needed */ } else { - LIST_INSERT_HEAD(&fn->downstream, me, entry); + RB_INSERT(lde_map_head, &fn->downstream, me); + me->head = &fn->downstream; if (fec_insert(&ln->recv_map, &me->fec)) log_warnx("failed to add %s to recv map", log_fec(&me->fec)); @@ -1180,7 +1191,7 @@ lde_map_free(void *ptr) { struct lde_map *map = ptr; - LIST_REMOVE(map, entry); + RB_REMOVE(lde_map_head, map->head, map); free(map); } diff --git a/ldpd/lde.h b/ldpd/lde.h index cf8f2129af..619310d126 100644 --- a/ldpd/lde.h +++ b/ldpd/lde.h @@ -61,10 +61,13 @@ struct lde_req { /* mapping entries */ struct lde_map { struct fec fec; - LIST_ENTRY(lde_map) entry; + struct lde_map_head *head; /* fec_node's upstream/downstream */ + RB_ENTRY(lde_map) entry; struct lde_nbr *nexthop; struct map map; }; +RB_HEAD(lde_map_head, lde_map); +RB_PROTOTYPE(lde_map_head, lde_map, entry, lde_map_cmp); /* withdraw entries */ struct lde_wdraw { @@ -110,8 +113,8 @@ struct fec_node { struct fec fec; LIST_HEAD(, fec_nh) nexthops; /* fib nexthops */ - LIST_HEAD(, lde_map) downstream; /* recv mappings */ - LIST_HEAD(, lde_map) upstream; /* sent mappings */ + struct lde_map_head downstream; /* recv mappings */ + struct lde_map_head upstream; /* sent mappings */ uint32_t local_label; void *data; /* fec specific data */ diff --git a/ldpd/lde_lib.c b/ldpd/lde_lib.c index 43e5f92f2f..faadd566ad 100644 --- a/ldpd/lde_lib.c +++ b/ldpd/lde_lib.c @@ -159,7 +159,7 @@ rt_dump(pid_t pid) RB_FOREACH(f, fec_tree, &ft) { fn = (struct fec_node *)f; if (fn->local_label == NO_LABEL && - LIST_EMPTY(&fn->downstream)) + RB_EMPTY(&fn->downstream)) continue; rtctl.first = 1; @@ -179,7 +179,7 @@ rt_dump(pid_t pid) } rtctl.local_label = fn->local_label; - LIST_FOREACH(me, &fn->downstream, entry) { + RB_FOREACH(me, lde_map_head, &fn->downstream) { rtctl.in_use = lde_nbr_is_nexthop(fn, me->nexthop); rtctl.nexthop = me->nexthop->id; rtctl.remote_label = me->map.label; @@ -188,7 +188,7 @@ rt_dump(pid_t pid) &rtctl, sizeof(rtctl)); rtctl.first = 0; } - if (LIST_EMPTY(&fn->downstream)) { + if (RB_EMPTY(&fn->downstream)) { rtctl.in_use = 0; rtctl.nexthop.s_addr = INADDR_ANY; rtctl.remote_label = NO_LABEL; @@ -224,10 +224,10 @@ fec_free(void *arg) while ((fnh = LIST_FIRST(&fn->nexthops))) fec_nh_del(fnh); - if (!LIST_EMPTY(&fn->downstream)) + if (!RB_EMPTY(&fn->downstream)) log_warnx("%s: fec %s downstream list not empty", __func__, log_fec(&fn->fec)); - if (!LIST_EMPTY(&fn->upstream)) + if (!RB_EMPTY(&fn->upstream)) log_warnx("%s: fec %s upstream list not empty", __func__, log_fec(&fn->fec)); @@ -251,8 +251,8 @@ fec_add(struct fec *fec) fn->fec = *fec; fn->local_label = NO_LABEL; - LIST_INIT(&fn->upstream); - LIST_INIT(&fn->downstream); + RB_INIT(&fn->upstream); + RB_INIT(&fn->downstream); LIST_INIT(&fn->nexthops); if (fec_insert(&ft, &fn->fec)) @@ -772,8 +772,8 @@ lde_gc_timer(struct thread *thread) fn = (struct fec_node *) fec; if (!LIST_EMPTY(&fn->nexthops) || - !LIST_EMPTY(&fn->downstream) || - !LIST_EMPTY(&fn->upstream)) + !RB_EMPTY(&fn->downstream) || + !RB_EMPTY(&fn->upstream)) continue; fec_remove(&ft, &fn->fec); From 39ec2dc9bb7d19262c264398cd1c9178fabb1862 Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Tue, 13 Dec 2016 15:29:35 -0200 Subject: [PATCH 13/27] ldpd: use red-black trees to store 'iface' elements Using red-black trees instead of linked lists brings the following benefits: 1 - Elements are naturally ordered (no need to reorder anything before outputting data to the user); 2 - Faster lookups/deletes: O(log n) time complexity against O(n). The insert operation with red-black trees is more expensive though, but that's not a big issue since lookups are much more frequent. Signed-off-by: Renato Westphal --- ldpd/interface.c | 37 +++++++++++++++++++++---------------- ldpd/lde.c | 4 ++-- ldpd/ldp_debug.c | 4 ++-- ldpd/ldp_vty_conf.c | 10 +++++----- ldpd/ldpd.c | 32 ++++++++++++++++---------------- ldpd/ldpd.h | 11 +++++++---- ldpd/ldpe.c | 8 ++++---- 7 files changed, 57 insertions(+), 49 deletions(-) diff --git a/ldpd/interface.c b/ldpd/interface.c index b6472fe5e8..06d36fef72 100644 --- a/ldpd/interface.c +++ b/ldpd/interface.c @@ -26,6 +26,7 @@ #include "sockopt.h" +static __inline int iface_compare(struct iface *, struct iface *); static struct if_addr *if_addr_new(struct kaddr *); static struct if_addr *if_addr_lookup(struct if_addr_head *, struct kaddr *); static int if_start(struct iface *, int); @@ -39,6 +40,14 @@ static int if_leave_ipv4_group(struct iface *, struct in_addr *); static int if_join_ipv6_group(struct iface *, struct in6_addr *); static int if_leave_ipv6_group(struct iface *, struct in6_addr *); +RB_GENERATE(iface_head, iface, entry, iface_compare) + +static __inline int +iface_compare(struct iface *a, struct iface *b) +{ + return (strcmp(a->name, b->name)); +} + struct iface * if_new(struct kif *kif) { @@ -69,18 +78,6 @@ if_new(struct kif *kif) return (iface); } -struct iface * -if_lookup(struct ldpd_conf *xconf, unsigned short ifindex) -{ - struct iface *iface; - - LIST_FOREACH(iface, &xconf->iface_list, entry) - if (iface->ifindex == ifindex) - return (iface); - - return (NULL); -} - void if_exit(struct iface *iface) { @@ -100,17 +97,25 @@ if_exit(struct iface *iface) } struct iface * -if_lookup_name(struct ldpd_conf *xconf, const char *ifname) +if_lookup(struct ldpd_conf *xconf, unsigned short ifindex) { struct iface *iface; - LIST_FOREACH(iface, &xconf->iface_list, entry) - if (strcmp(iface->name, ifname) == 0) + RB_FOREACH(iface, iface_head, &xconf->iface_tree) + if (iface->ifindex == ifindex) return (iface); return (NULL); } +struct iface * +if_lookup_name(struct ldpd_conf *xconf, const char *ifname) +{ + struct iface iface; + strlcpy(iface.name, ifname, sizeof(iface.name)); + return (RB_FIND(iface_head, &xconf->iface_tree, &iface)); +} + void if_update_info(struct iface *iface, struct kif *kif) { @@ -380,7 +385,7 @@ if_update_all(int af) { struct iface *iface; - LIST_FOREACH(iface, &leconf->iface_list, entry) + RB_FOREACH(iface, iface_head, &leconf->iface_tree) if_update(iface, af); } diff --git a/ldpd/lde.c b/ldpd/lde.c index 47bb326258..29e0fac327 100644 --- a/ldpd/lde.c +++ b/ldpd/lde.c @@ -472,7 +472,7 @@ lde_dispatch_parent(struct thread *thread) fatal(NULL); memcpy(nconf, imsg.data, sizeof(struct ldpd_conf)); - LIST_INIT(&nconf->iface_list); + RB_INIT(&nconf->iface_tree); LIST_INIT(&nconf->tnbr_list); LIST_INIT(&nconf->nbrp_list); LIST_INIT(&nconf->l2vpn_list); @@ -488,7 +488,7 @@ lde_dispatch_parent(struct thread *thread) niface->ipv4.iface = niface; niface->ipv6.iface = niface; - LIST_INSERT_HEAD(&nconf->iface_list, niface, entry); + RB_INSERT(iface_head, &nconf->iface_tree, niface); break; case IMSG_RECONF_TNBR: if ((ntnbr = malloc(sizeof(struct tnbr))) == NULL) diff --git a/ldpd/ldp_debug.c b/ldpd/ldp_debug.c index 15dd06a0f3..86b679d8aa 100644 --- a/ldpd/ldp_debug.c +++ b/ldpd/ldp_debug.c @@ -74,7 +74,7 @@ ldp_vty_debug(struct vty *vty, struct vty_arg *args[]) DEBUG_OFF(event, EVENT); else DEBUG_ON(event, EVENT); - } else if (strcmp(type_str, "messages") == 0) { + } else if (strcmp(type_str, "messages") == 0) { all = (vty_get_arg_value(args, "all")) ? 1 : 0; dir_str = vty_get_arg_value(args, "dir"); if (dir_str == NULL) @@ -99,7 +99,7 @@ ldp_vty_debug(struct vty *vty, struct vty_arg *args[]) DEBUG_ON(msg, MSG_SEND_ALL); } } - } else if (strcmp(type_str, "zebra") == 0) { + } else if (strcmp(type_str, "zebra") == 0) { if (disable) DEBUG_OFF(zebra, ZEBRA); else diff --git a/ldpd/ldp_vty_conf.c b/ldpd/ldp_vty_conf.c index e5acada180..e94de950d8 100644 --- a/ldpd/ldp_vty_conf.c +++ b/ldpd/ldp_vty_conf.c @@ -142,7 +142,7 @@ ldp_af_iface_config_write(struct vty *vty, int af) struct iface *iface; struct iface_af *ia; - LIST_FOREACH(iface, &ldpd_conf->iface_list, entry) { + RB_FOREACH(iface, iface_head, &ldpd_conf->iface_tree) { ia = iface_af_get(iface, af); if (!ia->enabled) continue; @@ -857,7 +857,7 @@ ldp_vty_interface(struct vty *vty, struct vty_arg *args[]) ia = iface_af_get(iface, af); ia->enabled = 1; - LIST_INSERT_HEAD(&vty_conf->iface_list, iface, entry); + RB_INSERT(iface_head, &vty_conf->iface_tree, iface); ldp_reload_ref(vty_conf, (void **)&iface); } else { memset(&kif, 0, sizeof(kif)); @@ -1648,14 +1648,14 @@ iface_new_api(struct ldpd_conf *conf, const char *name) } iface = if_new(&kif); - LIST_INSERT_HEAD(&conf->iface_list, iface, entry); + RB_INSERT(iface_head, &conf->iface_tree, iface); return (iface); } void -iface_del_api(struct iface *iface) +iface_del_api(struct ldpd_conf *conf, struct iface *iface) { - LIST_REMOVE(iface, entry); + RB_REMOVE(iface_head, &conf->iface_tree, iface); free(iface); } diff --git a/ldpd/ldpd.c b/ldpd/ldpd.c index 927af682a1..21456b4d1e 100644 --- a/ldpd/ldpd.c +++ b/ldpd/ldpd.c @@ -891,7 +891,7 @@ main_imsg_send_config(struct ldpd_conf *xconf) sizeof(*xconf)) == -1) return (-1); - LIST_FOREACH(iface, &xconf->iface_list, entry) { + RB_FOREACH(iface, iface_head, &xconf->iface_tree) { if (main_imsg_compose_both(IMSG_RECONF_IFACE, iface, sizeof(*iface)) == -1) return (-1); @@ -995,10 +995,10 @@ ldp_config_reset_main(struct ldpd_conf *conf, void **ref) struct iface *iface; struct nbr_params *nbrp; - while ((iface = LIST_FIRST(&conf->iface_list)) != NULL) { + while ((iface = RB_ROOT(&conf->iface_tree)) != NULL) { if (ref && *ref == iface) *ref = NULL; - LIST_REMOVE(iface, entry); + RB_REMOVE(iface_head, &conf->iface_tree, iface); free(iface); } @@ -1028,7 +1028,7 @@ ldp_config_reset_af(struct ldpd_conf *conf, int af, void **ref) struct iface_af *ia; struct tnbr *tnbr, *ttmp; - LIST_FOREACH(iface, &conf->iface_list, entry) { + RB_FOREACH(iface, iface_head, &conf->iface_tree) { ia = iface_af_get(iface, af); ia->enabled = 0; } @@ -1073,16 +1073,16 @@ ldp_dup_config_ref(struct ldpd_conf *conf, void **ref) } while (0) COPY(xconf, conf); - LIST_INIT(&xconf->iface_list); + RB_INIT(&xconf->iface_tree); LIST_INIT(&xconf->tnbr_list); LIST_INIT(&xconf->nbrp_list); LIST_INIT(&xconf->l2vpn_list); - LIST_FOREACH(iface, &conf->iface_list, entry) { + RB_FOREACH(iface, iface_head, &conf->iface_tree) { COPY(xi, iface); xi->ipv4.iface = xi; xi->ipv6.iface = xi; - LIST_INSERT_HEAD(&xconf->iface_list, xi, entry); + RB_INSERT(iface_head, &xconf->iface_tree, xi); } LIST_FOREACH(tnbr, &conf->tnbr_list, entry) { COPY(xt, tnbr); @@ -1134,8 +1134,8 @@ ldp_clear_config(struct ldpd_conf *xconf) struct nbr_params *nbrp; struct l2vpn *l2vpn; - while ((iface = LIST_FIRST(&xconf->iface_list)) != NULL) { - LIST_REMOVE(iface, entry); + while ((iface = RB_ROOT(&xconf->iface_tree)) != NULL) { + RB_REMOVE(iface_head, &xconf->iface_tree, iface); free(iface); } while ((tnbr = LIST_FIRST(&xconf->tnbr_list)) != NULL) { @@ -1277,10 +1277,10 @@ merge_ifaces(struct ldpd_conf *conf, struct ldpd_conf *xconf, void **ref) { struct iface *iface, *itmp, *xi; - LIST_FOREACH_SAFE(iface, &conf->iface_list, entry, itmp) { + RB_FOREACH_SAFE(iface, iface_head, &conf->iface_tree, itmp) { /* find deleted interfaces */ if ((xi = if_lookup_name(xconf, iface->name)) == NULL) { - LIST_REMOVE(iface, entry); + RB_REMOVE(iface_head, &conf->iface_tree, iface); switch (ldpd_process) { case PROC_LDE_ENGINE: @@ -1295,11 +1295,11 @@ merge_ifaces(struct ldpd_conf *conf, struct ldpd_conf *xconf, void **ref) free(iface); } } - LIST_FOREACH_SAFE(xi, &xconf->iface_list, entry, itmp) { + RB_FOREACH_SAFE(xi, iface_head, &xconf->iface_tree, itmp) { /* find new interfaces */ if ((iface = if_lookup_name(conf, xi->name)) == NULL) { - LIST_REMOVE(xi, entry); - LIST_INSERT_HEAD(&conf->iface_list, xi, entry); + RB_REMOVE(iface_head, &xconf->iface_tree, xi); + RB_INSERT(iface_head, &conf->iface_tree, xi); if (ldpd_process == PROC_MAIN) { QOBJ_REG (xi, iface); @@ -1312,7 +1312,7 @@ merge_ifaces(struct ldpd_conf *conf, struct ldpd_conf *xconf, void **ref) /* update existing interfaces */ merge_iface_af(&iface->ipv4, &xi->ipv4); merge_iface_af(&iface->ipv6, &xi->ipv6); - LIST_REMOVE(xi, entry); + RB_REMOVE(iface_head, &xconf->iface_tree, xi); if (ref && *ref == xi) *ref = iface; free(xi); @@ -1811,7 +1811,7 @@ config_new_empty(void) if (xconf == NULL) fatal(NULL); - LIST_INIT(&xconf->iface_list); + RB_INIT(&xconf->iface_tree); LIST_INIT(&xconf->tnbr_list); LIST_INIT(&xconf->nbrp_list); LIST_INIT(&xconf->l2vpn_list); diff --git a/ldpd/ldpd.h b/ldpd/ldpd.h index e58d8e4852..3e046447f2 100644 --- a/ldpd/ldpd.h +++ b/ldpd/ldpd.h @@ -264,7 +264,7 @@ struct iface_af { }; struct iface { - LIST_ENTRY(iface) entry; + RB_ENTRY(iface) entry; char name[IF_NAMESIZE]; unsigned int ifindex; struct if_addr_head addr_list; @@ -275,6 +275,8 @@ struct iface { struct iface_af ipv6; QOBJ_FIELDS }; +RB_HEAD(iface_head, iface); +RB_PROTOTYPE(iface_head, iface, entry, iface_compare); DECLARE_QOBJ_TYPE(iface) /* source of targeted hellos */ @@ -404,7 +406,7 @@ struct ldpd_conf { struct in_addr rtr_id; struct ldpd_af_conf ipv4; struct ldpd_af_conf ipv6; - LIST_HEAD(, iface) iface_list; + struct iface_head iface_tree; LIST_HEAD(, tnbr) tnbr_list; LIST_HEAD(, nbr_params) nbrp_list; LIST_HEAD(, l2vpn) l2vpn_list; @@ -627,9 +629,10 @@ void config_clear(struct ldpd_conf *); /* ldp_vty_conf.c */ /* NOTE: the parameters' names should be preserved because of codegen */ -struct iface *iface_new_api(struct ldpd_conf *cfg, +struct iface *iface_new_api(struct ldpd_conf *conf, const char *name); -void iface_del_api(struct iface *iface); +void iface_del_api(struct ldpd_conf *conf, + struct iface *iface); struct tnbr *tnbr_new_api(struct ldpd_conf *cfg, int af, union ldpd_addr *addr); void tnbr_del_api(struct tnbr *tnbr); diff --git a/ldpd/ldpe.c b/ldpd/ldpe.c index 0d0fe5c9e9..284d4cb35a 100644 --- a/ldpd/ldpe.c +++ b/ldpd/ldpe.c @@ -415,7 +415,7 @@ ldpe_dispatch_main(struct thread *thread) fatal(NULL); memcpy(nconf, imsg.data, sizeof(struct ldpd_conf)); - LIST_INIT(&nconf->iface_list); + RB_INIT(&nconf->iface_tree); LIST_INIT(&nconf->tnbr_list); LIST_INIT(&nconf->nbrp_list); LIST_INIT(&nconf->l2vpn_list); @@ -431,7 +431,7 @@ ldpe_dispatch_main(struct thread *thread) niface->ipv4.iface = niface; niface->ipv6.iface = niface; - LIST_INSERT_HEAD(&nconf->iface_list, niface, entry); + RB_INSERT(iface_head, &nconf->iface_tree, niface); break; case IMSG_RECONF_TNBR: if ((ntnbr = malloc(sizeof(struct tnbr))) == NULL) @@ -773,7 +773,7 @@ ldpe_iface_af_ctl(struct ctl_conn *c, int af, unsigned int idx) struct iface_af *ia; struct ctl_iface *ictl; - LIST_FOREACH(iface, &leconf->iface_list, entry) { + RB_FOREACH(iface, iface_head, &leconf->iface_tree) { if (idx == 0 || idx == iface->ifindex) { ia = iface_af_get(iface, af); if (!ia->enabled) @@ -806,7 +806,7 @@ ldpe_adj_ctl(struct ctl_conn *c) imsg_compose_event(&c->iev, IMSG_CTL_SHOW_DISCOVERY, 0, 0, -1, NULL, 0); - LIST_FOREACH(iface, &leconf->iface_list, entry) { + RB_FOREACH(iface, iface_head, &leconf->iface_tree) { memset(&ictl, 0, sizeof(ictl)); ictl.active_v4 = (iface->ipv4.state == IF_STA_ACTIVE); ictl.active_v6 = (iface->ipv6.state == IF_STA_ACTIVE); From 29f6e7acbe3309bf91e4666db6952512baed3ee0 Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Tue, 13 Dec 2016 16:19:15 -0200 Subject: [PATCH 14/27] ldpd: use red-black trees to store 'tnbr' elements Using red-black trees instead of linked lists brings the following benefits: 1 - Elements are naturally ordered (no need to reorder anything before outputting data to the user); 2 - Faster lookups/deletes: O(log n) time complexity against O(n). The insert operation with red-black trees is more expensive though, but that's not a big issue since lookups are much more frequent. Signed-off-by: Renato Westphal --- ldpd/adjacency.c | 40 +++++++++++++++++++++++++--------------- ldpd/hello.c | 4 ++-- ldpd/l2vpn.c | 4 ++-- ldpd/lde.c | 4 ++-- ldpd/ldp_vty_conf.c | 12 ++++++------ ldpd/ldpd.c | 34 +++++++++++++++++----------------- ldpd/ldpd.h | 10 ++++++---- ldpd/ldpe.c | 10 +++++----- ldpd/ldpe.h | 2 +- 9 files changed, 66 insertions(+), 54 deletions(-) diff --git a/ldpd/adjacency.c b/ldpd/adjacency.c index 3607ee96b3..f01f7a12fa 100644 --- a/ldpd/adjacency.c +++ b/ldpd/adjacency.c @@ -26,11 +26,14 @@ #include "log.h" static int adj_itimer(struct thread *); -static void tnbr_del(struct tnbr *); +static __inline int tnbr_compare(struct tnbr *, struct tnbr *); +static void tnbr_del(struct ldpd_conf *, struct tnbr *); static int tnbr_hello_timer(struct thread *); static void tnbr_start_hello_timer(struct tnbr *); static void tnbr_stop_hello_timer(struct tnbr *); +RB_GENERATE(tnbr_head, tnbr, entry, tnbr_compare) + struct adj * adj_new(struct in_addr lsr_id, struct hello_source *source, union ldpd_addr *addr) @@ -161,7 +164,7 @@ adj_itimer(struct thread *thread) if (!(adj->source.target->flags & F_TNBR_CONFIGURED) && adj->source.target->pw_count == 0) { /* remove dynamic targeted neighbor */ - tnbr_del(adj->source.target); + tnbr_del(leconf, adj->source.target); return (0); } adj->source.target->adj = NULL; @@ -188,6 +191,17 @@ adj_stop_itimer(struct adj *adj) /* targeted neighbors */ +static __inline int +tnbr_compare(struct tnbr *a, struct tnbr *b) +{ + if (a->af < b->af) + return (-1); + if (a->af > b->af) + return (1); + + return (ldp_addrcmp(a->af, &a->addr, &b->addr)); +} + struct tnbr * tnbr_new(int af, union ldpd_addr *addr) { @@ -204,34 +218,30 @@ tnbr_new(int af, union ldpd_addr *addr) } static void -tnbr_del(struct tnbr *tnbr) +tnbr_del(struct ldpd_conf *xconf, struct tnbr *tnbr) { tnbr_stop_hello_timer(tnbr); if (tnbr->adj) adj_del(tnbr->adj, S_SHUTDOWN); - LIST_REMOVE(tnbr, entry); + RB_REMOVE(tnbr_head, &xconf->tnbr_tree, tnbr); free(tnbr); } struct tnbr * tnbr_find(struct ldpd_conf *xconf, int af, union ldpd_addr *addr) { - struct tnbr *tnbr; - - LIST_FOREACH(tnbr, &xconf->tnbr_list, entry) - if (af == tnbr->af && - ldp_addrcmp(af, addr, &tnbr->addr) == 0) - return (tnbr); - - return (NULL); + struct tnbr tnbr; + tnbr.af = af; + tnbr.addr = *addr; + return (RB_FIND(tnbr_head, &xconf->tnbr_tree, &tnbr)); } struct tnbr * -tnbr_check(struct tnbr *tnbr) +tnbr_check(struct ldpd_conf *xconf, struct tnbr *tnbr) { if (!(tnbr->flags & (F_TNBR_CONFIGURED|F_TNBR_DYNAMIC)) && tnbr->pw_count == 0) { - tnbr_del(tnbr); + tnbr_del(xconf, tnbr); return (NULL); } @@ -276,7 +286,7 @@ tnbr_update_all(int af) struct tnbr *tnbr; /* update targeted neighbors */ - LIST_FOREACH(tnbr, &leconf->tnbr_list, entry) + RB_FOREACH(tnbr, tnbr_head, &leconf->tnbr_tree) if (tnbr->af == af || af == AF_UNSPEC) tnbr_update(tnbr); } diff --git a/ldpd/hello.c b/ldpd/hello.c index 755b25aa85..0833ebbafb 100644 --- a/ldpd/hello.c +++ b/ldpd/hello.c @@ -261,7 +261,7 @@ recv_hello(struct in_addr lsr_id, struct ldp_msg *msg, int af, if (tnbr && (tnbr->flags & F_TNBR_DYNAMIC) && !((flags & F_HELLO_REQ_TARG))) { tnbr->flags &= ~F_TNBR_DYNAMIC; - tnbr = tnbr_check(tnbr); + tnbr = tnbr_check(leconf, tnbr); } if (!tnbr) { @@ -273,7 +273,7 @@ recv_hello(struct in_addr lsr_id, struct ldp_msg *msg, int af, tnbr = tnbr_new(af, src); tnbr->flags |= F_TNBR_DYNAMIC; tnbr_update(tnbr); - LIST_INSERT_HEAD(&leconf->tnbr_list, tnbr, entry); + RB_INSERT(tnbr_head, &leconf->tnbr_tree, tnbr); } source.type = HELLO_TARGETED; diff --git a/ldpd/l2vpn.c b/ldpd/l2vpn.c index 3159d47dd8..b8c1728f63 100644 --- a/ldpd/l2vpn.c +++ b/ldpd/l2vpn.c @@ -530,7 +530,7 @@ ldpe_l2vpn_pw_init(struct l2vpn_pw *pw) if (tnbr == NULL) { tnbr = tnbr_new(pw->af, &pw->addr); tnbr_update(tnbr); - LIST_INSERT_HEAD(&leconf->tnbr_list, tnbr, entry); + RB_INSERT(tnbr_head, &leconf->tnbr_tree, tnbr); } tnbr->pw_count++; @@ -544,6 +544,6 @@ ldpe_l2vpn_pw_exit(struct l2vpn_pw *pw) tnbr = tnbr_find(leconf, pw->af, &pw->addr); if (tnbr) { tnbr->pw_count--; - tnbr_check(tnbr); + tnbr_check(leconf, tnbr); } } diff --git a/ldpd/lde.c b/ldpd/lde.c index 29e0fac327..8b1632f334 100644 --- a/ldpd/lde.c +++ b/ldpd/lde.c @@ -473,7 +473,7 @@ lde_dispatch_parent(struct thread *thread) memcpy(nconf, imsg.data, sizeof(struct ldpd_conf)); RB_INIT(&nconf->iface_tree); - LIST_INIT(&nconf->tnbr_list); + RB_INIT(&nconf->tnbr_tree); LIST_INIT(&nconf->nbrp_list); LIST_INIT(&nconf->l2vpn_list); break; @@ -495,7 +495,7 @@ lde_dispatch_parent(struct thread *thread) fatal(NULL); memcpy(ntnbr, imsg.data, sizeof(struct tnbr)); - LIST_INSERT_HEAD(&nconf->tnbr_list, ntnbr, entry); + RB_INSERT(tnbr_head, &nconf->tnbr_tree, ntnbr); break; case IMSG_RECONF_NBRP: if ((nnbrp = malloc(sizeof(struct nbr_params))) == NULL) diff --git a/ldpd/ldp_vty_conf.c b/ldpd/ldp_vty_conf.c index e94de950d8..4283ee93cc 100644 --- a/ldpd/ldp_vty_conf.c +++ b/ldpd/ldp_vty_conf.c @@ -213,7 +213,7 @@ ldp_af_config_write(struct vty *vty, int af, struct ldpd_conf *conf, vty_out(vty, " session holdtime %u%s", af_conf->keepalive, VTY_NEWLINE); - LIST_FOREACH(tnbr, &ldpd_conf->tnbr_list, entry) { + RB_FOREACH(tnbr, tnbr_head, &ldpd_conf->tnbr_tree) { if (tnbr->af == af) { vty_out(vty, " !%s", VTY_NEWLINE); vty_out(vty, " neighbor %s targeted%s", @@ -955,7 +955,7 @@ ldp_vty_neighbor_targeted(struct vty *vty, struct vty_arg *args[]) if (tnbr == NULL) goto cancel; - LIST_REMOVE(tnbr, entry); + RB_REMOVE(tnbr_head, &vty_conf->tnbr_tree, tnbr); free(tnbr); ldp_reload(vty_conf); return (CMD_SUCCESS); @@ -966,7 +966,7 @@ ldp_vty_neighbor_targeted(struct vty *vty, struct vty_arg *args[]) tnbr = tnbr_new(af, &addr); tnbr->flags |= F_TNBR_CONFIGURED; - LIST_INSERT_HEAD(&vty_conf->tnbr_list, tnbr, entry); + RB_INSERT(tnbr_head, &vty_conf->tnbr_tree, tnbr); ldp_reload(vty_conf); @@ -1672,14 +1672,14 @@ tnbr_new_api(struct ldpd_conf *conf, int af, union ldpd_addr *addr) tnbr = tnbr_new(af, addr); tnbr->flags |= F_TNBR_CONFIGURED; - LIST_INSERT_HEAD(&conf->tnbr_list, tnbr, entry); + RB_INSERT(tnbr_head, &conf->tnbr_tree, tnbr); return (tnbr); } void -tnbr_del_api(struct tnbr *tnbr) +tnbr_del_api(struct ldpd_conf *conf, struct tnbr *tnbr) { - LIST_REMOVE(tnbr, entry); + RB_REMOVE(tnbr_head, &conf->tnbr_tree, tnbr); free(tnbr); } diff --git a/ldpd/ldpd.c b/ldpd/ldpd.c index 21456b4d1e..63cdfe6884 100644 --- a/ldpd/ldpd.c +++ b/ldpd/ldpd.c @@ -897,7 +897,7 @@ main_imsg_send_config(struct ldpd_conf *xconf) return (-1); } - LIST_FOREACH(tnbr, &xconf->tnbr_list, entry) { + RB_FOREACH(tnbr, tnbr_head, &xconf->tnbr_tree) { if (main_imsg_compose_both(IMSG_RECONF_TNBR, tnbr, sizeof(*tnbr)) == -1) return (-1); @@ -1033,13 +1033,13 @@ ldp_config_reset_af(struct ldpd_conf *conf, int af, void **ref) ia->enabled = 0; } - LIST_FOREACH_SAFE(tnbr, &conf->tnbr_list, entry, ttmp) { + RB_FOREACH_SAFE(tnbr, tnbr_head, &conf->tnbr_tree, ttmp) { if (tnbr->af != af) continue; if (ref && *ref == tnbr) *ref = NULL; - LIST_REMOVE(tnbr, entry); + RB_REMOVE(tnbr_head, &conf->tnbr_tree, tnbr); free(tnbr); } @@ -1074,7 +1074,7 @@ ldp_dup_config_ref(struct ldpd_conf *conf, void **ref) COPY(xconf, conf); RB_INIT(&xconf->iface_tree); - LIST_INIT(&xconf->tnbr_list); + RB_INIT(&xconf->tnbr_tree); LIST_INIT(&xconf->nbrp_list); LIST_INIT(&xconf->l2vpn_list); @@ -1084,9 +1084,9 @@ ldp_dup_config_ref(struct ldpd_conf *conf, void **ref) xi->ipv6.iface = xi; RB_INSERT(iface_head, &xconf->iface_tree, xi); } - LIST_FOREACH(tnbr, &conf->tnbr_list, entry) { + RB_FOREACH(tnbr, tnbr_head, &conf->tnbr_tree) { COPY(xt, tnbr); - LIST_INSERT_HEAD(&xconf->tnbr_list, xt, entry); + RB_INSERT(tnbr_head, &xconf->tnbr_tree, xt); } LIST_FOREACH(nbrp, &conf->nbrp_list, entry) { COPY(xn, nbrp); @@ -1138,8 +1138,8 @@ ldp_clear_config(struct ldpd_conf *xconf) RB_REMOVE(iface_head, &xconf->iface_tree, iface); free(iface); } - while ((tnbr = LIST_FIRST(&xconf->tnbr_list)) != NULL) { - LIST_REMOVE(tnbr, entry); + while ((tnbr = RB_ROOT(&xconf->tnbr_tree)) != NULL) { + RB_REMOVE(tnbr_head, &xconf->tnbr_tree, tnbr); free(tnbr); } while ((nbrp = LIST_FIRST(&xconf->nbrp_list)) != NULL) { @@ -1336,7 +1336,7 @@ merge_tnbrs(struct ldpd_conf *conf, struct ldpd_conf *xconf, void **ref) { struct tnbr *tnbr, *ttmp, *xt; - LIST_FOREACH_SAFE(tnbr, &conf->tnbr_list, entry, ttmp) { + RB_FOREACH_SAFE(tnbr, tnbr_head, &conf->tnbr_tree, ttmp) { if (!(tnbr->flags & F_TNBR_CONFIGURED)) continue; @@ -1344,26 +1344,26 @@ merge_tnbrs(struct ldpd_conf *conf, struct ldpd_conf *xconf, void **ref) if ((xt = tnbr_find(xconf, tnbr->af, &tnbr->addr)) == NULL) { switch (ldpd_process) { case PROC_LDE_ENGINE: - LIST_REMOVE(tnbr, entry); + RB_REMOVE(tnbr_head, &conf->tnbr_tree, tnbr); free(tnbr); break; case PROC_LDP_ENGINE: tnbr->flags &= ~F_TNBR_CONFIGURED; - tnbr_check(tnbr); + tnbr_check(conf, tnbr); break; case PROC_MAIN: - LIST_REMOVE(tnbr, entry); + RB_REMOVE(tnbr_head, &conf->tnbr_tree, tnbr); QOBJ_UNREG (tnbr); free(tnbr); break; } } } - LIST_FOREACH_SAFE(xt, &xconf->tnbr_list, entry, ttmp) { + RB_FOREACH_SAFE(xt, tnbr_head, &xconf->tnbr_tree, ttmp) { /* find new tnbrs */ if ((tnbr = tnbr_find(conf, xt->af, &xt->addr)) == NULL) { - LIST_REMOVE(xt, entry); - LIST_INSERT_HEAD(&conf->tnbr_list, xt, entry); + RB_REMOVE(tnbr_head, &xconf->tnbr_tree, xt); + RB_INSERT(tnbr_head, &conf->tnbr_tree, xt); switch (ldpd_process) { case PROC_LDE_ENGINE: @@ -1381,7 +1381,7 @@ merge_tnbrs(struct ldpd_conf *conf, struct ldpd_conf *xconf, void **ref) /* update existing tnbrs */ if (!(tnbr->flags & F_TNBR_CONFIGURED)) tnbr->flags |= F_TNBR_CONFIGURED; - LIST_REMOVE(xt, entry); + RB_REMOVE(tnbr_head, &xconf->tnbr_tree, xt); if (ref && *ref == xt) *ref = tnbr; free(xt); @@ -1812,7 +1812,7 @@ config_new_empty(void) fatal(NULL); RB_INIT(&xconf->iface_tree); - LIST_INIT(&xconf->tnbr_list); + RB_INIT(&xconf->tnbr_tree); LIST_INIT(&xconf->nbrp_list); LIST_INIT(&xconf->l2vpn_list); diff --git a/ldpd/ldpd.h b/ldpd/ldpd.h index 3e046447f2..55c61b6ef5 100644 --- a/ldpd/ldpd.h +++ b/ldpd/ldpd.h @@ -281,7 +281,7 @@ DECLARE_QOBJ_TYPE(iface) /* source of targeted hellos */ struct tnbr { - LIST_ENTRY(tnbr) entry; + RB_ENTRY(tnbr) entry; struct thread *hello_timer; struct adj *adj; int af; @@ -291,6 +291,8 @@ struct tnbr { uint8_t flags; QOBJ_FIELDS }; +RB_HEAD(tnbr_head, tnbr); +RB_PROTOTYPE(tnbr_head, tnbr, entry, tnbr_compare); DECLARE_QOBJ_TYPE(tnbr) #define F_TNBR_CONFIGURED 0x01 #define F_TNBR_DYNAMIC 0x02 @@ -407,7 +409,7 @@ struct ldpd_conf { struct ldpd_af_conf ipv4; struct ldpd_af_conf ipv6; struct iface_head iface_tree; - LIST_HEAD(, tnbr) tnbr_list; + struct tnbr_head tnbr_tree; LIST_HEAD(, nbr_params) nbrp_list; LIST_HEAD(, l2vpn) l2vpn_list; uint16_t lhello_holdtime; @@ -633,9 +635,9 @@ struct iface *iface_new_api(struct ldpd_conf *conf, const char *name); void iface_del_api(struct ldpd_conf *conf, struct iface *iface); -struct tnbr *tnbr_new_api(struct ldpd_conf *cfg, int af, +struct tnbr *tnbr_new_api(struct ldpd_conf *conf, int af, union ldpd_addr *addr); -void tnbr_del_api(struct tnbr *tnbr); +void tnbr_del_api(struct ldpd_conf *conf, struct tnbr *tnbr); struct nbr_params *nbrp_new_api(struct ldpd_conf *cfg, struct in_addr lsr_id); void nbrp_del_api(struct nbr_params *nbrp); diff --git a/ldpd/ldpe.c b/ldpd/ldpe.c index 284d4cb35a..159f584715 100644 --- a/ldpd/ldpe.c +++ b/ldpd/ldpe.c @@ -416,7 +416,7 @@ ldpe_dispatch_main(struct thread *thread) memcpy(nconf, imsg.data, sizeof(struct ldpd_conf)); RB_INIT(&nconf->iface_tree); - LIST_INIT(&nconf->tnbr_list); + RB_INIT(&nconf->tnbr_tree); LIST_INIT(&nconf->nbrp_list); LIST_INIT(&nconf->l2vpn_list); break; @@ -438,7 +438,7 @@ ldpe_dispatch_main(struct thread *thread) fatal(NULL); memcpy(ntnbr, imsg.data, sizeof(struct tnbr)); - LIST_INSERT_HEAD(&nconf->tnbr_list, ntnbr, entry); + RB_INSERT(tnbr_head, &nconf->tnbr_tree, ntnbr); break; case IMSG_RECONF_NBRP: if ((nnbrp = malloc(sizeof(struct nbr_params))) == NULL) @@ -744,12 +744,12 @@ ldpe_remove_dynamic_tnbrs(int af) { struct tnbr *tnbr, *safe; - LIST_FOREACH_SAFE(tnbr, &leconf->tnbr_list, entry, safe) { + RB_FOREACH_SAFE(tnbr, tnbr_head, &leconf->tnbr_tree, safe) { if (tnbr->af != af) continue; tnbr->flags &= ~F_TNBR_DYNAMIC; - tnbr_check(tnbr); + tnbr_check(leconf, tnbr); } } @@ -833,7 +833,7 @@ ldpe_adj_ctl(struct ctl_conn *c) } } - LIST_FOREACH(tnbr, &leconf->tnbr_list, entry) { + RB_FOREACH(tnbr, tnbr_head, &leconf->tnbr_tree) { memset(&tctl, 0, sizeof(tctl)); tctl.af = tnbr->af; tctl.addr = tnbr->addr; diff --git a/ldpd/ldpe.h b/ldpd/ldpe.h index da90c7cad7..a57727591a 100644 --- a/ldpd/ldpe.h +++ b/ldpd/ldpe.h @@ -225,7 +225,7 @@ void adj_start_itimer(struct adj *); void adj_stop_itimer(struct adj *); struct tnbr *tnbr_new(int, union ldpd_addr *); struct tnbr *tnbr_find(struct ldpd_conf *, int, union ldpd_addr *); -struct tnbr *tnbr_check(struct tnbr *); +struct tnbr *tnbr_check(struct ldpd_conf *, struct tnbr *); void tnbr_update(struct tnbr *); void tnbr_update_all(int); uint16_t tnbr_get_hello_holdtime(struct tnbr *); From c485351c5222f0e1106709d77329597d30165a03 Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Wed, 14 Dec 2016 09:14:52 -0200 Subject: [PATCH 15/27] ldpd: use red-black trees to store 'nbr_params' elements Using red-black trees instead of linked lists brings the following benefits: 1 - Elements are naturally ordered (no need to reorder anything before outputting data to the user); 2 - Faster lookups/deletes: O(log n) time complexity against O(n). The insert operation with red-black trees is more expensive though, but that's not a big issue since lookups are much more frequent. Signed-off-by: Renato Westphal --- ldpd/lde.c | 4 ++-- ldpd/ldp_vty_conf.c | 14 +++++++------- ldpd/ldpd.c | 30 +++++++++++++++--------------- ldpd/ldpd.h | 11 +++++++---- ldpd/ldpe.c | 4 ++-- ldpd/neighbor.c | 19 ++++++++++++------- 6 files changed, 45 insertions(+), 37 deletions(-) diff --git a/ldpd/lde.c b/ldpd/lde.c index 8b1632f334..e137c01ddf 100644 --- a/ldpd/lde.c +++ b/ldpd/lde.c @@ -474,7 +474,7 @@ lde_dispatch_parent(struct thread *thread) RB_INIT(&nconf->iface_tree); RB_INIT(&nconf->tnbr_tree); - LIST_INIT(&nconf->nbrp_list); + RB_INIT(&nconf->nbrp_tree); LIST_INIT(&nconf->l2vpn_list); break; case IMSG_RECONF_IFACE: @@ -502,7 +502,7 @@ lde_dispatch_parent(struct thread *thread) fatal(NULL); memcpy(nnbrp, imsg.data, sizeof(struct nbr_params)); - LIST_INSERT_HEAD(&nconf->nbrp_list, nnbrp, entry); + RB_INSERT(nbrp_head, &nconf->nbrp_tree, nnbrp); break; case IMSG_RECONF_L2VPN: if ((nl2vpn = malloc(sizeof(struct l2vpn))) == NULL) diff --git a/ldpd/ldp_vty_conf.c b/ldpd/ldp_vty_conf.c index 4283ee93cc..0145817d58 100644 --- a/ldpd/ldp_vty_conf.c +++ b/ldpd/ldp_vty_conf.c @@ -265,7 +265,7 @@ ldp_config_write(struct vty *vty) if (ldpd_conf->flags & F_LDPD_DS_CISCO_INTEROP) vty_out(vty, " dual-stack cisco-interop%s", VTY_NEWLINE); - LIST_FOREACH(nbrp, &ldpd_conf->nbrp_list, entry) { + RB_FOREACH(nbrp, nbrp_head, &ldpd_conf->nbrp_tree) { if (nbrp->flags & F_NBRP_KEEPALIVE) vty_out(vty, " neighbor %s session holdtime %u%s", inet_ntoa(nbrp->lsr_id), nbrp->keepalive, @@ -740,7 +740,7 @@ ldp_vty_nbr_session_holdtime(struct vty *vty, struct vty_arg *args[]) } else { if (nbrp == NULL) { nbrp = nbr_params_new(lsr_id); - LIST_INSERT_HEAD(&vty_conf->nbrp_list, nbrp, entry); + RB_INSERT(nbrp_head, &vty_conf->nbrp_tree, nbrp); } else if (nbrp->keepalive == secs) goto cancel; @@ -1129,7 +1129,7 @@ ldp_vty_neighbor_password(struct vty *vty, struct vty_arg *args[]) } else { if (nbrp == NULL) { nbrp = nbr_params_new(lsr_id); - LIST_INSERT_HEAD(&vty_conf->nbrp_list, nbrp, entry); + RB_INSERT(nbrp_head, &vty_conf->nbrp_tree, nbrp); } else if (nbrp->auth.method == AUTH_MD5SIG && strcmp(nbrp->auth.md5key, password_str) == 0) goto cancel; @@ -1195,7 +1195,7 @@ ldp_vty_neighbor_ttl_security(struct vty *vty, struct vty_arg *args[]) } else { if (nbrp == NULL) { nbrp = nbr_params_new(lsr_id); - LIST_INSERT_HEAD(&vty_conf->nbrp_list, nbrp, entry); + RB_INSERT(nbrp_head, &vty_conf->nbrp_tree, nbrp); } nbrp->flags |= F_NBRP_GTSM; @@ -1692,14 +1692,14 @@ nbrp_new_api(struct ldpd_conf *conf, struct in_addr lsr_id) return (NULL); nbrp = nbr_params_new(lsr_id); - LIST_INSERT_HEAD(&conf->nbrp_list, nbrp, entry); + RB_INSERT(nbrp_head, &conf->nbrp_tree, nbrp); return (nbrp); } void -nbrp_del_api(struct nbr_params *nbrp) +nbrp_del_api(struct ldpd_conf *conf, struct nbr_params *nbrp) { - LIST_REMOVE(nbrp, entry); + RB_REMOVE(nbrp_head, &conf->nbrp_tree, nbrp); free(nbrp); } diff --git a/ldpd/ldpd.c b/ldpd/ldpd.c index 63cdfe6884..c1cef540e0 100644 --- a/ldpd/ldpd.c +++ b/ldpd/ldpd.c @@ -903,7 +903,7 @@ main_imsg_send_config(struct ldpd_conf *xconf) return (-1); } - LIST_FOREACH(nbrp, &xconf->nbrp_list, entry) { + RB_FOREACH(nbrp, nbrp_head, &xconf->nbrp_tree) { if (main_imsg_compose_both(IMSG_RECONF_NBRP, nbrp, sizeof(*nbrp)) == -1) return (-1); @@ -1002,10 +1002,10 @@ ldp_config_reset_main(struct ldpd_conf *conf, void **ref) free(iface); } - while ((nbrp = LIST_FIRST(&conf->nbrp_list)) != NULL) { + while ((nbrp = RB_ROOT(&conf->nbrp_tree)) != NULL) { if (ref && *ref == nbrp) *ref = NULL; - LIST_REMOVE(nbrp, entry); + RB_REMOVE(nbrp_head, &conf->nbrp_tree, nbrp); free(nbrp); } @@ -1075,7 +1075,7 @@ ldp_dup_config_ref(struct ldpd_conf *conf, void **ref) COPY(xconf, conf); RB_INIT(&xconf->iface_tree); RB_INIT(&xconf->tnbr_tree); - LIST_INIT(&xconf->nbrp_list); + RB_INIT(&xconf->nbrp_tree); LIST_INIT(&xconf->l2vpn_list); RB_FOREACH(iface, iface_head, &conf->iface_tree) { @@ -1088,9 +1088,9 @@ ldp_dup_config_ref(struct ldpd_conf *conf, void **ref) COPY(xt, tnbr); RB_INSERT(tnbr_head, &xconf->tnbr_tree, xt); } - LIST_FOREACH(nbrp, &conf->nbrp_list, entry) { + RB_FOREACH(nbrp, nbrp_head, &conf->nbrp_tree) { COPY(xn, nbrp); - LIST_INSERT_HEAD(&xconf->nbrp_list, xn, entry); + RB_INSERT(nbrp_head, &xconf->nbrp_tree, xn); } LIST_FOREACH(l2vpn, &conf->l2vpn_list, entry) { COPY(xl, l2vpn); @@ -1142,8 +1142,8 @@ ldp_clear_config(struct ldpd_conf *xconf) RB_REMOVE(tnbr_head, &xconf->tnbr_tree, tnbr); free(tnbr); } - while ((nbrp = LIST_FIRST(&xconf->nbrp_list)) != NULL) { - LIST_REMOVE(nbrp, entry); + while ((nbrp = RB_ROOT(&xconf->nbrp_tree)) != NULL) { + RB_REMOVE(nbrp_head, &xconf->nbrp_tree, nbrp); free(nbrp); } while ((l2vpn = LIST_FIRST(&xconf->l2vpn_list)) != NULL) { @@ -1395,7 +1395,7 @@ merge_nbrps(struct ldpd_conf *conf, struct ldpd_conf *xconf, void **ref) struct nbr *nbr; int nbrp_changed; - LIST_FOREACH_SAFE(nbrp, &conf->nbrp_list, entry, ntmp) { + RB_FOREACH_SAFE(nbrp, nbrp_head, &conf->nbrp_tree, ntmp) { /* find deleted nbrps */ if ((xn = nbr_params_find(xconf, nbrp->lsr_id)) == NULL) { switch (ldpd_process) { @@ -1421,15 +1421,15 @@ merge_nbrps(struct ldpd_conf *conf, struct ldpd_conf *xconf, void **ref) QOBJ_UNREG (nbrp); break; } - LIST_REMOVE(nbrp, entry); + RB_REMOVE(nbrp_head, &conf->nbrp_tree, nbrp); free(nbrp); } } - LIST_FOREACH_SAFE(xn, &xconf->nbrp_list, entry, ntmp) { + RB_FOREACH_SAFE(xn, nbrp_head, &xconf->nbrp_tree, ntmp) { /* find new nbrps */ if ((nbrp = nbr_params_find(conf, xn->lsr_id)) == NULL) { - LIST_REMOVE(xn, entry); - LIST_INSERT_HEAD(&conf->nbrp_list, xn, entry); + RB_REMOVE(nbrp_head, &xconf->nbrp_tree, xn); + RB_INSERT(nbrp_head, &conf->nbrp_tree, xn); switch (ldpd_process) { case PROC_LDE_ENGINE: @@ -1496,7 +1496,7 @@ merge_nbrps(struct ldpd_conf *conf, struct ldpd_conf *xconf, void **ref) nbr_establish_connection(nbr); } } - LIST_REMOVE(xn, entry); + RB_REMOVE(nbrp_head, &xconf->nbrp_tree, xn); if (ref && *ref == xn) *ref = nbrp; free(xn); @@ -1813,7 +1813,7 @@ config_new_empty(void) RB_INIT(&xconf->iface_tree); RB_INIT(&xconf->tnbr_tree); - LIST_INIT(&xconf->nbrp_list); + RB_INIT(&xconf->nbrp_tree); LIST_INIT(&xconf->l2vpn_list); return (xconf); diff --git a/ldpd/ldpd.h b/ldpd/ldpd.h index 55c61b6ef5..248d9e7f6c 100644 --- a/ldpd/ldpd.h +++ b/ldpd/ldpd.h @@ -304,7 +304,7 @@ enum auth_method { /* neighbor specific parameters */ struct nbr_params { - LIST_ENTRY(nbr_params) entry; + RB_ENTRY(nbr_params) entry; struct in_addr lsr_id; uint16_t keepalive; int gtsm_enabled; @@ -317,6 +317,8 @@ struct nbr_params { uint8_t flags; QOBJ_FIELDS }; +RB_HEAD(nbrp_head, nbr_params); +RB_PROTOTYPE(nbrp_head, nbr_params, entry, nbr_params_compare); DECLARE_QOBJ_TYPE(nbr_params) #define F_NBRP_KEEPALIVE 0x01 #define F_NBRP_GTSM 0x02 @@ -410,7 +412,7 @@ struct ldpd_conf { struct ldpd_af_conf ipv6; struct iface_head iface_tree; struct tnbr_head tnbr_tree; - LIST_HEAD(, nbr_params) nbrp_list; + struct nbrp_head nbrp_tree; LIST_HEAD(, l2vpn) l2vpn_list; uint16_t lhello_holdtime; uint16_t lhello_interval; @@ -638,9 +640,10 @@ void iface_del_api(struct ldpd_conf *conf, struct tnbr *tnbr_new_api(struct ldpd_conf *conf, int af, union ldpd_addr *addr); void tnbr_del_api(struct ldpd_conf *conf, struct tnbr *tnbr); -struct nbr_params *nbrp_new_api(struct ldpd_conf *cfg, +struct nbr_params *nbrp_new_api(struct ldpd_conf *conf, struct in_addr lsr_id); -void nbrp_del_api(struct nbr_params *nbrp); +void nbrp_del_api(struct ldpd_conf *conf, + struct nbr_params *nbrp); struct l2vpn *l2vpn_new_api(struct ldpd_conf *cfg, const char *name); void l2vpn_del_api(struct l2vpn *l2vpn); struct l2vpn_if *l2vpn_if_new_api(struct ldpd_conf *conf, diff --git a/ldpd/ldpe.c b/ldpd/ldpe.c index 159f584715..76988cb701 100644 --- a/ldpd/ldpe.c +++ b/ldpd/ldpe.c @@ -417,7 +417,7 @@ ldpe_dispatch_main(struct thread *thread) RB_INIT(&nconf->iface_tree); RB_INIT(&nconf->tnbr_tree); - LIST_INIT(&nconf->nbrp_list); + RB_INIT(&nconf->nbrp_tree); LIST_INIT(&nconf->l2vpn_list); break; case IMSG_RECONF_IFACE: @@ -445,7 +445,7 @@ ldpe_dispatch_main(struct thread *thread) fatal(NULL); memcpy(nnbrp, imsg.data, sizeof(struct nbr_params)); - LIST_INSERT_HEAD(&nconf->nbrp_list, nnbrp, entry); + RB_INSERT(nbrp_head, &nconf->nbrp_tree, nnbrp); break; case IMSG_RECONF_L2VPN: if ((nl2vpn = malloc(sizeof(struct l2vpn))) == NULL) diff --git a/ldpd/neighbor.c b/ldpd/neighbor.c index 8376a01549..5addc4dda2 100644 --- a/ldpd/neighbor.c +++ b/ldpd/neighbor.c @@ -39,10 +39,13 @@ static void nbr_start_itimeout(struct nbr *); static int nbr_idtimer(struct thread *); static int nbr_act_session_operational(struct nbr *); static void nbr_send_labelmappings(struct nbr *); +static __inline int nbr_params_compare(struct nbr_params *, + struct nbr_params *); RB_GENERATE(nbr_id_head, nbr, id_tree, nbr_id_compare) RB_GENERATE(nbr_addr_head, nbr, addr_tree, nbr_addr_compare) RB_GENERATE(nbr_pid_head, nbr, pid_tree, nbr_pid_compare) +RB_GENERATE(nbrp_head, nbr_params, entry, nbr_params_compare) struct { int state; @@ -752,6 +755,12 @@ nbr_send_labelmappings(struct nbr *nbr) NULL, 0); } +static __inline int +nbr_params_compare(struct nbr_params *a, struct nbr_params *b) +{ + return (ntohl(a->lsr_id.s_addr) - ntohl(b->lsr_id.s_addr)); +} + struct nbr_params * nbr_params_new(struct in_addr lsr_id) { @@ -769,13 +778,9 @@ nbr_params_new(struct in_addr lsr_id) struct nbr_params * nbr_params_find(struct ldpd_conf *xconf, struct in_addr lsr_id) { - struct nbr_params *nbrp; - - LIST_FOREACH(nbrp, &xconf->nbrp_list, entry) - if (nbrp->lsr_id.s_addr == lsr_id.s_addr) - return (nbrp); - - return (NULL); + struct nbr_params nbrp; + nbrp.lsr_id = lsr_id; + return (RB_FIND(nbrp_head, &xconf->nbrp_tree, &nbrp)); } uint16_t From 2db4e1fca180987dec09a165b2e064fa14a50298 Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Wed, 14 Dec 2016 10:42:45 -0200 Subject: [PATCH 16/27] ldpd: use red-black trees to store 'l2vpn' elements Using red-black trees instead of linked lists brings the following benefits: 1 - Elements are naturally ordered (no need to reorder anything before outputting data to the user); 2 - Faster lookups/deletes: O(log n) time complexity against O(n). The insert operation with red-black trees is more expensive though, but that's not a big issue since lookups are much more frequent. Signed-off-by: Renato Westphal --- ldpd/l2vpn.c | 25 +++++++++++++++---------- ldpd/lde.c | 4 ++-- ldpd/ldp_vty_conf.c | 14 +++++++------- ldpd/ldpd.c | 28 ++++++++++++++-------------- ldpd/ldpd.h | 11 +++++++---- ldpd/ldpe.c | 4 ++-- 6 files changed, 47 insertions(+), 39 deletions(-) diff --git a/ldpd/l2vpn.c b/ldpd/l2vpn.c index b8c1728f63..6c8ce0396d 100644 --- a/ldpd/l2vpn.c +++ b/ldpd/l2vpn.c @@ -26,7 +26,16 @@ #include "lde.h" #include "log.h" -static void l2vpn_pw_fec(struct l2vpn_pw *, struct fec *); +static void l2vpn_pw_fec(struct l2vpn_pw *, struct fec *); +static __inline int l2vpn_compare(struct l2vpn *, struct l2vpn *); + +RB_GENERATE(l2vpn_head, l2vpn, entry, l2vpn_compare) + +static __inline int +l2vpn_compare(struct l2vpn *a, struct l2vpn *b) +{ + return (strcmp(a->name, b->name)); +} struct l2vpn * l2vpn_new(const char *name) @@ -52,13 +61,9 @@ l2vpn_new(const char *name) struct l2vpn * l2vpn_find(struct ldpd_conf *xconf, const char *name) { - struct l2vpn *l2vpn; - - LIST_FOREACH(l2vpn, &xconf->l2vpn_list, entry) - if (strcmp(l2vpn->name, name) == 0) - return (l2vpn); - - return (NULL); + struct l2vpn l2vpn; + strlcpy(l2vpn.name, name, sizeof(l2vpn.name)); + return (RB_FIND(l2vpn_head, &xconf->l2vpn_tree, &l2vpn)); } void @@ -399,7 +404,7 @@ l2vpn_sync_pws(int af, union ldpd_addr *addr) struct fec_node *fn; struct fec_nh *fnh; - LIST_FOREACH(l2vpn, &ldeconf->l2vpn_list, entry) { + RB_FOREACH(l2vpn, l2vpn_head, &ldeconf->l2vpn_tree) { LIST_FOREACH(pw, &l2vpn->pw_list, entry) { if (af != pw->af || ldp_addrcmp(af, &pw->addr, addr)) continue; @@ -428,7 +433,7 @@ l2vpn_pw_ctl(pid_t pid) struct l2vpn_pw *pw; static struct ctl_pw pwctl; - LIST_FOREACH(l2vpn, &ldeconf->l2vpn_list, entry) + RB_FOREACH(l2vpn, l2vpn_head, &ldeconf->l2vpn_tree) LIST_FOREACH(pw, &l2vpn->pw_list, entry) { memset(&pwctl, 0, sizeof(pwctl)); strlcpy(pwctl.l2vpn_name, pw->l2vpn->name, diff --git a/ldpd/lde.c b/ldpd/lde.c index e137c01ddf..948aa1b48d 100644 --- a/ldpd/lde.c +++ b/ldpd/lde.c @@ -475,7 +475,7 @@ lde_dispatch_parent(struct thread *thread) RB_INIT(&nconf->iface_tree); RB_INIT(&nconf->tnbr_tree); RB_INIT(&nconf->nbrp_tree); - LIST_INIT(&nconf->l2vpn_list); + RB_INIT(&nconf->l2vpn_tree); break; case IMSG_RECONF_IFACE: if ((niface = malloc(sizeof(struct iface))) == NULL) @@ -513,7 +513,7 @@ lde_dispatch_parent(struct thread *thread) LIST_INIT(&nl2vpn->pw_list); LIST_INIT(&nl2vpn->pw_inactive_list); - LIST_INSERT_HEAD(&nconf->l2vpn_list, nl2vpn, entry); + RB_INSERT(l2vpn_head, &nconf->l2vpn_tree, nl2vpn); break; case IMSG_RECONF_L2VPN_IF: if ((nlif = malloc(sizeof(struct l2vpn_if))) == NULL) diff --git a/ldpd/ldp_vty_conf.c b/ldpd/ldp_vty_conf.c index 0145817d58..50f5f63bc5 100644 --- a/ldpd/ldp_vty_conf.c +++ b/ldpd/ldp_vty_conf.c @@ -341,7 +341,7 @@ ldp_l2vpn_config_write(struct vty *vty) struct l2vpn_if *lif; struct l2vpn_pw *pw; - LIST_FOREACH(l2vpn, &ldpd_conf->l2vpn_list, entry) { + RB_FOREACH(l2vpn, l2vpn_head, &ldpd_conf->l2vpn_tree) { vty_out(vty, "l2vpn %s type vpls%s", l2vpn->name, VTY_NEWLINE); if (l2vpn->pw_type != DEFAULT_PW_TYPE) @@ -393,7 +393,7 @@ ldp_iface_is_configured(struct ldpd_conf *xconf, const char *ifname) if (if_lookup_name(xconf, ifname)) return (1); - LIST_FOREACH(l2vpn, &xconf->l2vpn_list, entry) { + RB_FOREACH(l2vpn, l2vpn_head, &xconf->l2vpn_tree) { if (l2vpn_if_find_name(l2vpn, ifname)) return (1); if (l2vpn_pw_find_name(l2vpn, ifname)) @@ -1235,7 +1235,7 @@ ldp_vty_l2vpn(struct vty *vty, struct vty_arg *args[]) if (l2vpn == NULL) goto cancel; - LIST_REMOVE(l2vpn, entry); + RB_REMOVE(l2vpn_head, &vty_conf->l2vpn_tree, l2vpn); l2vpn_del(l2vpn); ldp_reload(vty_conf); return (CMD_SUCCESS); @@ -1248,7 +1248,7 @@ ldp_vty_l2vpn(struct vty *vty, struct vty_arg *args[]) l2vpn = l2vpn_new(name_str); l2vpn->type = L2VPN_TYPE_VPLS; - LIST_INSERT_HEAD(&vty_conf->l2vpn_list, l2vpn, entry); + RB_INSERT(l2vpn_head, &vty_conf->l2vpn_tree, l2vpn); ldp_reload(vty_conf); VTY_PUSH_CONTEXT(LDP_L2VPN_NODE, l2vpn); @@ -1713,12 +1713,12 @@ l2vpn_new_api(struct ldpd_conf *conf, const char *name) l2vpn = l2vpn_new(name); l2vpn->type = L2VPN_TYPE_VPLS; - LIST_INSERT_HEAD(&conf->l2vpn_list, l2vpn, entry); + RB_INSERT(l2vpn_head, &conf->l2vpn_tree, l2vpn); return (l2vpn); } void -l2vpn_del_api(struct l2vpn *l2vpn) +l2vpn_del_api(struct ldpd_conf *conf, struct l2vpn *l2vpn) { struct l2vpn_if *lif; struct l2vpn_pw *pw; @@ -1735,7 +1735,7 @@ l2vpn_del_api(struct l2vpn *l2vpn) LIST_REMOVE(pw, entry); free(pw); } - LIST_REMOVE(l2vpn, entry); + RB_REMOVE(l2vpn_head, &conf->l2vpn_tree, l2vpn); free(l2vpn); } diff --git a/ldpd/ldpd.c b/ldpd/ldpd.c index c1cef540e0..1375b26721 100644 --- a/ldpd/ldpd.c +++ b/ldpd/ldpd.c @@ -909,7 +909,7 @@ main_imsg_send_config(struct ldpd_conf *xconf) return (-1); } - LIST_FOREACH(l2vpn, &xconf->l2vpn_list, entry) { + RB_FOREACH(l2vpn, l2vpn_head, &xconf->l2vpn_tree) { if (main_imsg_compose_both(IMSG_RECONF_L2VPN, l2vpn, sizeof(*l2vpn)) == -1) return (-1); @@ -971,7 +971,7 @@ ldp_config_normalize(struct ldpd_conf *xconf, void **ref) ldp_config_reset_af(xconf, AF_INET6, ref); } - LIST_FOREACH(l2vpn, &xconf->l2vpn_list, entry) { + RB_FOREACH(l2vpn, l2vpn_head, &xconf->l2vpn_tree) { LIST_FOREACH(pw, &l2vpn->pw_list, entry) { if (pw->flags & F_PW_STATIC_NBR_ADDR) continue; @@ -1076,7 +1076,7 @@ ldp_dup_config_ref(struct ldpd_conf *conf, void **ref) RB_INIT(&xconf->iface_tree); RB_INIT(&xconf->tnbr_tree); RB_INIT(&xconf->nbrp_tree); - LIST_INIT(&xconf->l2vpn_list); + RB_INIT(&xconf->l2vpn_tree); RB_FOREACH(iface, iface_head, &conf->iface_tree) { COPY(xi, iface); @@ -1092,12 +1092,12 @@ ldp_dup_config_ref(struct ldpd_conf *conf, void **ref) COPY(xn, nbrp); RB_INSERT(nbrp_head, &xconf->nbrp_tree, xn); } - LIST_FOREACH(l2vpn, &conf->l2vpn_list, entry) { + RB_FOREACH(l2vpn, l2vpn_head, &conf->l2vpn_tree) { COPY(xl, l2vpn); LIST_INIT(&xl->if_list); LIST_INIT(&xl->pw_list); LIST_INIT(&xl->pw_inactive_list); - LIST_INSERT_HEAD(&xconf->l2vpn_list, xl, entry); + RB_INSERT(l2vpn_head, &xconf->l2vpn_tree, xl); LIST_FOREACH(lif, &l2vpn->if_list, entry) { COPY(xf, lif); @@ -1146,8 +1146,8 @@ ldp_clear_config(struct ldpd_conf *xconf) RB_REMOVE(nbrp_head, &xconf->nbrp_tree, nbrp); free(nbrp); } - while ((l2vpn = LIST_FIRST(&xconf->l2vpn_list)) != NULL) { - LIST_REMOVE(l2vpn, entry); + while ((l2vpn = RB_ROOT(&xconf->l2vpn_tree)) != NULL) { + RB_REMOVE(l2vpn_head, &xconf->l2vpn_tree, l2vpn); l2vpn_del(l2vpn); } @@ -1510,10 +1510,10 @@ merge_l2vpns(struct ldpd_conf *conf, struct ldpd_conf *xconf, void **ref) struct l2vpn_if *lif; struct l2vpn_pw *pw; - LIST_FOREACH_SAFE(l2vpn, &conf->l2vpn_list, entry, ltmp) { + RB_FOREACH_SAFE(l2vpn, l2vpn_head, &conf->l2vpn_tree, ltmp) { /* find deleted l2vpns */ if ((xl = l2vpn_find(xconf, l2vpn->name)) == NULL) { - LIST_REMOVE(l2vpn, entry); + RB_REMOVE(l2vpn_head, &conf->l2vpn_tree, l2vpn); switch (ldpd_process) { case PROC_LDE_ENGINE: @@ -1535,11 +1535,11 @@ merge_l2vpns(struct ldpd_conf *conf, struct ldpd_conf *xconf, void **ref) l2vpn_del(l2vpn); } } - LIST_FOREACH_SAFE(xl, &xconf->l2vpn_list, entry, ltmp) { + RB_FOREACH_SAFE(xl, l2vpn_head, &xconf->l2vpn_tree, ltmp) { /* find new l2vpns */ if ((l2vpn = l2vpn_find(conf, xl->name)) == NULL) { - LIST_REMOVE(xl, entry); - LIST_INSERT_HEAD(&conf->l2vpn_list, xl, entry); + RB_REMOVE(l2vpn_head, &xconf->l2vpn_tree, xl); + RB_INSERT(l2vpn_head, &conf->l2vpn_tree, xl); switch (ldpd_process) { case PROC_LDE_ENGINE: @@ -1557,7 +1557,7 @@ merge_l2vpns(struct ldpd_conf *conf, struct ldpd_conf *xconf, void **ref) /* update existing l2vpns */ merge_l2vpn(conf, l2vpn, xl, ref); - LIST_REMOVE(xl, entry); + RB_REMOVE(l2vpn_head, &xconf->l2vpn_tree, xl); if (ref && *ref == xl) *ref = l2vpn; free(xl); @@ -1814,7 +1814,7 @@ config_new_empty(void) RB_INIT(&xconf->iface_tree); RB_INIT(&xconf->tnbr_tree); RB_INIT(&xconf->nbrp_tree); - LIST_INIT(&xconf->l2vpn_list); + RB_INIT(&xconf->l2vpn_tree); return (xconf); } diff --git a/ldpd/ldpd.h b/ldpd/ldpd.h index 248d9e7f6c..6c702287dd 100644 --- a/ldpd/ldpd.h +++ b/ldpd/ldpd.h @@ -358,7 +358,7 @@ DECLARE_QOBJ_TYPE(l2vpn_pw) #define F_PW_STATIC_NBR_ADDR 0x20 /* static neighbor address configured */ struct l2vpn { - LIST_ENTRY(l2vpn) entry; + RB_ENTRY(l2vpn) entry; char name[L2VPN_NAME_LEN]; int type; int pw_type; @@ -370,6 +370,8 @@ struct l2vpn { LIST_HEAD(, l2vpn_pw) pw_inactive_list; QOBJ_FIELDS }; +RB_HEAD(l2vpn_head, l2vpn); +RB_PROTOTYPE(l2vpn_head, l2vpn, entry, l2vpn_compare); DECLARE_QOBJ_TYPE(l2vpn) #define L2VPN_TYPE_VPWS 1 #define L2VPN_TYPE_VPLS 2 @@ -413,7 +415,7 @@ struct ldpd_conf { struct iface_head iface_tree; struct tnbr_head tnbr_tree; struct nbrp_head nbrp_tree; - LIST_HEAD(, l2vpn) l2vpn_list; + struct l2vpn_head l2vpn_tree; uint16_t lhello_holdtime; uint16_t lhello_interval; uint16_t thello_holdtime; @@ -644,8 +646,9 @@ struct nbr_params *nbrp_new_api(struct ldpd_conf *conf, struct in_addr lsr_id); void nbrp_del_api(struct ldpd_conf *conf, struct nbr_params *nbrp); -struct l2vpn *l2vpn_new_api(struct ldpd_conf *cfg, const char *name); -void l2vpn_del_api(struct l2vpn *l2vpn); +struct l2vpn *l2vpn_new_api(struct ldpd_conf *conf, const char *name); +void l2vpn_del_api(struct ldpd_conf *conf, + struct l2vpn *l2vpn); struct l2vpn_if *l2vpn_if_new_api(struct ldpd_conf *conf, struct l2vpn *l2vpn, const char *ifname); void l2vpn_if_del_api(struct l2vpn_if *lif); diff --git a/ldpd/ldpe.c b/ldpd/ldpe.c index 76988cb701..54f4fef599 100644 --- a/ldpd/ldpe.c +++ b/ldpd/ldpe.c @@ -418,7 +418,7 @@ ldpe_dispatch_main(struct thread *thread) RB_INIT(&nconf->iface_tree); RB_INIT(&nconf->tnbr_tree); RB_INIT(&nconf->nbrp_tree); - LIST_INIT(&nconf->l2vpn_list); + RB_INIT(&nconf->l2vpn_tree); break; case IMSG_RECONF_IFACE: if ((niface = malloc(sizeof(struct iface))) == NULL) @@ -456,7 +456,7 @@ ldpe_dispatch_main(struct thread *thread) LIST_INIT(&nl2vpn->pw_list); LIST_INIT(&nl2vpn->pw_inactive_list); - LIST_INSERT_HEAD(&nconf->l2vpn_list, nl2vpn, entry); + RB_INSERT(l2vpn_head, &nconf->l2vpn_tree, nl2vpn); break; case IMSG_RECONF_L2VPN_IF: if ((nlif = malloc(sizeof(struct l2vpn_if))) == NULL) From 7a09a2b1c4a888bd97b43bf5fc31383ca59e4352 Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Wed, 14 Dec 2016 12:34:57 -0200 Subject: [PATCH 17/27] ldpd: use red-black trees to store 'l2vpn_if' elements Using red-black trees instead of linked lists brings the following benefits: 1 - Elements are naturally ordered (no need to reorder anything before outputting data to the user); 2 - Faster lookups/deletes: O(log n) time complexity against O(n). The insert operation with red-black trees is more expensive though, but that's not a big issue since lookups are much more frequent. Signed-off-by: Renato Westphal --- ldpd/l2vpn.c | 26 +++++++++++++++----------- ldpd/lde.c | 4 ++-- ldpd/ldp_vty_conf.c | 16 ++++++++-------- ldpd/ldpd.c | 22 +++++++++++----------- ldpd/ldpd.h | 9 ++++++--- ldpd/ldpe.c | 4 ++-- 6 files changed, 44 insertions(+), 37 deletions(-) diff --git a/ldpd/l2vpn.c b/ldpd/l2vpn.c index 6c8ce0396d..0382bedf87 100644 --- a/ldpd/l2vpn.c +++ b/ldpd/l2vpn.c @@ -28,8 +28,10 @@ static void l2vpn_pw_fec(struct l2vpn_pw *, struct fec *); static __inline int l2vpn_compare(struct l2vpn *, struct l2vpn *); +static __inline int l2vpn_if_compare(struct l2vpn_if *, struct l2vpn_if *); RB_GENERATE(l2vpn_head, l2vpn, entry, l2vpn_compare) +RB_GENERATE(l2vpn_if_head, l2vpn_if, entry, l2vpn_if_compare) static __inline int l2vpn_compare(struct l2vpn *a, struct l2vpn *b) @@ -51,7 +53,7 @@ l2vpn_new(const char *name) l2vpn->mtu = DEFAULT_L2VPN_MTU; l2vpn->pw_type = DEFAULT_PW_TYPE; - LIST_INIT(&l2vpn->if_list); + RB_INIT(&l2vpn->if_tree); LIST_INIT(&l2vpn->pw_list); LIST_INIT(&l2vpn->pw_inactive_list); @@ -72,8 +74,8 @@ l2vpn_del(struct l2vpn *l2vpn) struct l2vpn_if *lif; struct l2vpn_pw *pw; - while ((lif = LIST_FIRST(&l2vpn->if_list)) != NULL) { - LIST_REMOVE(lif, entry); + while ((lif = RB_ROOT(&l2vpn->if_tree)) != NULL) { + RB_REMOVE(l2vpn_if_head, &l2vpn->if_tree, lif); free(lif); } while ((pw = LIST_FIRST(&l2vpn->pw_list)) != NULL) { @@ -106,6 +108,12 @@ l2vpn_exit(struct l2vpn *l2vpn) l2vpn_pw_exit(pw); } +static __inline int +l2vpn_if_compare(struct l2vpn_if *a, struct l2vpn_if *b) +{ + return (strcmp(a->ifname, b->ifname)); +} + struct l2vpn_if * l2vpn_if_new(struct l2vpn *l2vpn, struct kif *kif) { @@ -127,7 +135,7 @@ l2vpn_if_find(struct l2vpn *l2vpn, unsigned int ifindex) { struct l2vpn_if *lif; - LIST_FOREACH(lif, &l2vpn->if_list, entry) + RB_FOREACH(lif, l2vpn_if_head, &l2vpn->if_tree) if (lif->ifindex == ifindex) return (lif); @@ -137,13 +145,9 @@ l2vpn_if_find(struct l2vpn *l2vpn, unsigned int ifindex) struct l2vpn_if * l2vpn_if_find_name(struct l2vpn *l2vpn, const char *ifname) { - struct l2vpn_if *lif; - - LIST_FOREACH(lif, &l2vpn->if_list, entry) - if (strcmp(lif->ifname, ifname) == 0) - return (lif); - - return (NULL); + struct l2vpn_if lif; + strlcpy(lif.ifname, ifname, sizeof(lif.ifname)); + return (RB_FIND(l2vpn_if_head, &l2vpn->if_tree, &lif)); } diff --git a/ldpd/lde.c b/ldpd/lde.c index 948aa1b48d..76d56010f5 100644 --- a/ldpd/lde.c +++ b/ldpd/lde.c @@ -509,7 +509,7 @@ lde_dispatch_parent(struct thread *thread) fatal(NULL); memcpy(nl2vpn, imsg.data, sizeof(struct l2vpn)); - LIST_INIT(&nl2vpn->if_list); + RB_INIT(&nl2vpn->if_tree); LIST_INIT(&nl2vpn->pw_list); LIST_INIT(&nl2vpn->pw_inactive_list); @@ -521,7 +521,7 @@ lde_dispatch_parent(struct thread *thread) memcpy(nlif, imsg.data, sizeof(struct l2vpn_if)); nlif->l2vpn = nl2vpn; - LIST_INSERT_HEAD(&nl2vpn->if_list, nlif, entry); + RB_INSERT(l2vpn_if_head, &nl2vpn->if_tree, nlif); break; case IMSG_RECONF_L2VPN_PW: if ((npw = malloc(sizeof(struct l2vpn_pw))) == NULL) diff --git a/ldpd/ldp_vty_conf.c b/ldpd/ldp_vty_conf.c index 50f5f63bc5..317fe3f2cb 100644 --- a/ldpd/ldp_vty_conf.c +++ b/ldpd/ldp_vty_conf.c @@ -354,7 +354,7 @@ ldp_l2vpn_config_write(struct vty *vty) vty_out(vty, " bridge %s%s", l2vpn->br_ifname, VTY_NEWLINE); - LIST_FOREACH(lif, &l2vpn->if_list, entry) + RB_FOREACH(lif, l2vpn_if_head, &l2vpn->if_tree) vty_out(vty, " member interface %s%s", lif->ifname, VTY_NEWLINE); @@ -1369,7 +1369,7 @@ ldp_vty_l2vpn_interface(struct vty *vty, struct vty_arg *args[]) if (lif == NULL) goto cancel; - LIST_REMOVE(lif, entry); + RB_REMOVE(l2vpn_if_head, &l2vpn->if_tree, lif); free(lif); ldp_reload(vty_conf); return (CMD_SUCCESS); @@ -1392,7 +1392,7 @@ ldp_vty_l2vpn_interface(struct vty *vty, struct vty_arg *args[]) } lif = l2vpn_if_new(l2vpn, &kif); - LIST_INSERT_HEAD(&l2vpn->if_list, lif, entry); + RB_INSERT(l2vpn_if_head, &l2vpn->if_tree, lif); ldp_reload_ref(vty_conf, (void **)&l2vpn); @@ -1723,8 +1723,8 @@ l2vpn_del_api(struct ldpd_conf *conf, struct l2vpn *l2vpn) struct l2vpn_if *lif; struct l2vpn_pw *pw; - while ((lif = LIST_FIRST(&l2vpn->if_list)) != NULL) { - LIST_REMOVE(lif, entry); + while ((lif = RB_ROOT(&l2vpn->if_tree)) != NULL) { + RB_REMOVE(l2vpn_if_head, &l2vpn->if_tree, lif); free(lif); } while ((pw = LIST_FIRST(&l2vpn->pw_list)) != NULL) { @@ -1759,14 +1759,14 @@ l2vpn_if_new_api(struct ldpd_conf *conf, struct l2vpn *l2vpn, } lif = l2vpn_if_new(l2vpn, &kif); - LIST_INSERT_HEAD(&l2vpn->if_list, lif, entry); + RB_INSERT(l2vpn_if_head, &l2vpn->if_tree, lif); return (lif); } void -l2vpn_if_del_api(struct l2vpn_if *lif) +l2vpn_if_del_api(struct l2vpn *l2vpn, struct l2vpn_if *lif) { - LIST_REMOVE(lif, entry); + RB_REMOVE(l2vpn_if_head, &l2vpn->if_tree, lif); free(lif); } diff --git a/ldpd/ldpd.c b/ldpd/ldpd.c index 1375b26721..dce62801e7 100644 --- a/ldpd/ldpd.c +++ b/ldpd/ldpd.c @@ -914,7 +914,7 @@ main_imsg_send_config(struct ldpd_conf *xconf) sizeof(*l2vpn)) == -1) return (-1); - LIST_FOREACH(lif, &l2vpn->if_list, entry) { + RB_FOREACH(lif, l2vpn_if_head, &l2vpn->if_tree) { if (main_imsg_compose_both(IMSG_RECONF_L2VPN_IF, lif, sizeof(*lif)) == -1) return (-1); @@ -1094,15 +1094,15 @@ ldp_dup_config_ref(struct ldpd_conf *conf, void **ref) } RB_FOREACH(l2vpn, l2vpn_head, &conf->l2vpn_tree) { COPY(xl, l2vpn); - LIST_INIT(&xl->if_list); + RB_INIT(&xl->if_tree); LIST_INIT(&xl->pw_list); LIST_INIT(&xl->pw_inactive_list); RB_INSERT(l2vpn_head, &xconf->l2vpn_tree, xl); - LIST_FOREACH(lif, &l2vpn->if_list, entry) { + RB_FOREACH(lif, l2vpn_if_head, &l2vpn->if_tree) { COPY(xf, lif); xf->l2vpn = xl; - LIST_INSERT_HEAD(&xl->if_list, xf, entry); + RB_INSERT(l2vpn_if_head, &xl->if_tree, xf); } LIST_FOREACH(pw, &l2vpn->pw_list, entry) { COPY(xp, pw); @@ -1523,7 +1523,7 @@ merge_l2vpns(struct ldpd_conf *conf, struct ldpd_conf *xconf, void **ref) ldpe_l2vpn_exit(l2vpn); break; case PROC_MAIN: - LIST_FOREACH(lif, &l2vpn->if_list, entry) + RB_FOREACH(lif, l2vpn_if_head, &l2vpn->if_tree) QOBJ_UNREG (lif); LIST_FOREACH(pw, &l2vpn->pw_list, entry) QOBJ_UNREG (pw); @@ -1578,27 +1578,27 @@ merge_l2vpn(struct ldpd_conf *xconf, struct l2vpn *l2vpn, struct l2vpn *xl, void previous_mtu = l2vpn->mtu; /* merge intefaces */ - LIST_FOREACH_SAFE(lif, &l2vpn->if_list, entry, ftmp) { + RB_FOREACH_SAFE(lif, l2vpn_if_head, &l2vpn->if_tree, ftmp) { /* find deleted interfaces */ if ((xf = l2vpn_if_find_name(xl, lif->ifname)) == NULL) { if (ldpd_process == PROC_MAIN) QOBJ_UNREG (lif); - LIST_REMOVE(lif, entry); + RB_REMOVE(l2vpn_if_head, &l2vpn->if_tree, lif); free(lif); } } - LIST_FOREACH_SAFE(xf, &xl->if_list, entry, ftmp) { + RB_FOREACH_SAFE(xf, l2vpn_if_head, &xl->if_tree, ftmp) { /* find new interfaces */ if ((lif = l2vpn_if_find_name(l2vpn, xf->ifname)) == NULL) { - LIST_REMOVE(xf, entry); - LIST_INSERT_HEAD(&l2vpn->if_list, xf, entry); + RB_REMOVE(l2vpn_if_head, &xl->if_tree, xf); + RB_INSERT(l2vpn_if_head, &l2vpn->if_tree, xf); xf->l2vpn = l2vpn; if (ldpd_process == PROC_MAIN) QOBJ_REG (xf, l2vpn_if); continue; } - LIST_REMOVE(xf, entry); + RB_REMOVE(l2vpn_if_head, &xl->if_tree, xf); if (ref && *ref == xf) *ref = lif; free(xf); diff --git a/ldpd/ldpd.h b/ldpd/ldpd.h index 6c702287dd..9bda8ed218 100644 --- a/ldpd/ldpd.h +++ b/ldpd/ldpd.h @@ -325,13 +325,15 @@ DECLARE_QOBJ_TYPE(nbr_params) #define F_NBRP_GTSM_HOPS 0x04 struct l2vpn_if { - LIST_ENTRY(l2vpn_if) entry; + RB_ENTRY(l2vpn_if) entry; struct l2vpn *l2vpn; char ifname[IF_NAMESIZE]; unsigned int ifindex; uint16_t flags; QOBJ_FIELDS }; +RB_HEAD(l2vpn_if_head, l2vpn_if); +RB_PROTOTYPE(l2vpn_if_head, l2vpn_if, entry, l2vpn_if_compare); DECLARE_QOBJ_TYPE(l2vpn_if) struct l2vpn_pw { @@ -365,7 +367,7 @@ struct l2vpn { int mtu; char br_ifname[IF_NAMESIZE]; unsigned int br_ifindex; - LIST_HEAD(, l2vpn_if) if_list; + struct l2vpn_if_head if_tree; LIST_HEAD(, l2vpn_pw) pw_list; LIST_HEAD(, l2vpn_pw) pw_inactive_list; QOBJ_FIELDS @@ -651,7 +653,8 @@ void l2vpn_del_api(struct ldpd_conf *conf, struct l2vpn *l2vpn); struct l2vpn_if *l2vpn_if_new_api(struct ldpd_conf *conf, struct l2vpn *l2vpn, const char *ifname); -void l2vpn_if_del_api(struct l2vpn_if *lif); +void l2vpn_if_del_api(struct l2vpn *l2vpn, + struct l2vpn_if *lif); struct l2vpn_pw *l2vpn_pw_new_api(struct ldpd_conf *conf, struct l2vpn *l2vpn, const char *ifname); void l2vpn_pw_del_api(struct l2vpn_pw *pw); diff --git a/ldpd/ldpe.c b/ldpd/ldpe.c index 54f4fef599..103a1ec412 100644 --- a/ldpd/ldpe.c +++ b/ldpd/ldpe.c @@ -452,7 +452,7 @@ ldpe_dispatch_main(struct thread *thread) fatal(NULL); memcpy(nl2vpn, imsg.data, sizeof(struct l2vpn)); - LIST_INIT(&nl2vpn->if_list); + RB_INIT(&nl2vpn->if_tree); LIST_INIT(&nl2vpn->pw_list); LIST_INIT(&nl2vpn->pw_inactive_list); @@ -464,7 +464,7 @@ ldpe_dispatch_main(struct thread *thread) memcpy(nlif, imsg.data, sizeof(struct l2vpn_if)); nlif->l2vpn = nl2vpn; - LIST_INSERT_HEAD(&nl2vpn->if_list, nlif, entry); + RB_INSERT(l2vpn_if_head, &nl2vpn->if_tree, nlif); break; case IMSG_RECONF_L2VPN_PW: if ((npw = malloc(sizeof(struct l2vpn_pw))) == NULL) From a3cb56d84a5a0e71f9e0f96e476b857ff4f2942e Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Wed, 14 Dec 2016 13:53:07 -0200 Subject: [PATCH 18/27] ldpd: use red-black trees to store 'l2vpn_pw' elements Using red-black trees instead of linked lists brings the following benefits: 1 - Elements are naturally ordered (no need to reorder anything before outputting data to the user); 2 - Faster lookups/deletes: O(log n) time complexity against O(n). The insert operation with red-black trees is more expensive though, but that's not a big issue since lookups are much more frequent. Signed-off-by: Renato Westphal --- ldpd/l2vpn.c | 49 ++++++++++++++++++--------------- ldpd/lde.c | 8 +++--- ldpd/ldp_vty_conf.c | 22 +++++++-------- ldpd/ldpd.c | 66 ++++++++++++++++++++++----------------------- ldpd/ldpd.h | 11 +++++--- ldpd/ldpe.c | 8 +++--- 6 files changed, 86 insertions(+), 78 deletions(-) diff --git a/ldpd/l2vpn.c b/ldpd/l2vpn.c index 0382bedf87..0c2b91dbf0 100644 --- a/ldpd/l2vpn.c +++ b/ldpd/l2vpn.c @@ -29,9 +29,11 @@ static void l2vpn_pw_fec(struct l2vpn_pw *, struct fec *); static __inline int l2vpn_compare(struct l2vpn *, struct l2vpn *); static __inline int l2vpn_if_compare(struct l2vpn_if *, struct l2vpn_if *); +static __inline int l2vpn_pw_compare(struct l2vpn_pw *, struct l2vpn_pw *); RB_GENERATE(l2vpn_head, l2vpn, entry, l2vpn_compare) RB_GENERATE(l2vpn_if_head, l2vpn_if, entry, l2vpn_if_compare) +RB_GENERATE(l2vpn_pw_head, l2vpn_pw, entry, l2vpn_pw_compare) static __inline int l2vpn_compare(struct l2vpn *a, struct l2vpn *b) @@ -54,8 +56,8 @@ l2vpn_new(const char *name) l2vpn->pw_type = DEFAULT_PW_TYPE; RB_INIT(&l2vpn->if_tree); - LIST_INIT(&l2vpn->pw_list); - LIST_INIT(&l2vpn->pw_inactive_list); + RB_INIT(&l2vpn->pw_tree); + RB_INIT(&l2vpn->pw_inactive_tree); return (l2vpn); } @@ -78,12 +80,12 @@ l2vpn_del(struct l2vpn *l2vpn) RB_REMOVE(l2vpn_if_head, &l2vpn->if_tree, lif); free(lif); } - while ((pw = LIST_FIRST(&l2vpn->pw_list)) != NULL) { - LIST_REMOVE(pw, entry); + while ((pw = RB_ROOT(&l2vpn->pw_tree)) != NULL) { + RB_REMOVE(l2vpn_pw_head, &l2vpn->pw_tree, pw); free(pw); } - while ((pw = LIST_FIRST(&l2vpn->pw_inactive_list)) != NULL) { - LIST_REMOVE(pw, entry); + while ((pw = RB_ROOT(&l2vpn->pw_inactive_tree)) != NULL) { + RB_REMOVE(l2vpn_pw_head, &l2vpn->pw_inactive_tree, pw); free(pw); } @@ -95,7 +97,7 @@ l2vpn_init(struct l2vpn *l2vpn) { struct l2vpn_pw *pw; - LIST_FOREACH(pw, &l2vpn->pw_list, entry) + RB_FOREACH(pw, l2vpn_pw_head, &l2vpn->pw_tree) l2vpn_pw_init(pw); } @@ -104,7 +106,7 @@ l2vpn_exit(struct l2vpn *l2vpn) { struct l2vpn_pw *pw; - LIST_FOREACH(pw, &l2vpn->pw_list, entry) + RB_FOREACH(pw, l2vpn_pw_head, &l2vpn->pw_tree) l2vpn_pw_exit(pw); } @@ -150,6 +152,11 @@ l2vpn_if_find_name(struct l2vpn *l2vpn, const char *ifname) return (RB_FIND(l2vpn_if_head, &l2vpn->if_tree, &lif)); } +static __inline int +l2vpn_pw_compare(struct l2vpn_pw *a, struct l2vpn_pw *b) +{ + return (strcmp(a->ifname, b->ifname)); +} struct l2vpn_pw * l2vpn_pw_new(struct l2vpn *l2vpn, struct kif *kif) @@ -171,10 +178,10 @@ l2vpn_pw_find(struct l2vpn *l2vpn, unsigned int ifindex) { struct l2vpn_pw *pw; - LIST_FOREACH(pw, &l2vpn->pw_list, entry) + RB_FOREACH(pw, l2vpn_pw_head, &l2vpn->pw_tree) if (pw->ifindex == ifindex) return (pw); - LIST_FOREACH(pw, &l2vpn->pw_inactive_list, entry) + RB_FOREACH(pw, l2vpn_pw_head, &l2vpn->pw_inactive_tree) if (pw->ifindex == ifindex) return (pw); @@ -185,15 +192,13 @@ struct l2vpn_pw * l2vpn_pw_find_name(struct l2vpn *l2vpn, const char *ifname) { struct l2vpn_pw *pw; + struct l2vpn_pw s; - LIST_FOREACH(pw, &l2vpn->pw_list, entry) - if (strcmp(pw->ifname, ifname) == 0) - return (pw); - LIST_FOREACH(pw, &l2vpn->pw_inactive_list, entry) - if (strcmp(pw->ifname, ifname) == 0) - return (pw); - - return (NULL); + strlcpy(s.ifname, ifname, sizeof(s.ifname)); + pw = RB_FIND(l2vpn_pw_head, &l2vpn->pw_tree, &s); + if (pw) + return (pw); + return (RB_FIND(l2vpn_pw_head, &l2vpn->pw_inactive_tree, &s)); } void @@ -409,7 +414,7 @@ l2vpn_sync_pws(int af, union ldpd_addr *addr) struct fec_nh *fnh; RB_FOREACH(l2vpn, l2vpn_head, &ldeconf->l2vpn_tree) { - LIST_FOREACH(pw, &l2vpn->pw_list, entry) { + RB_FOREACH(pw, l2vpn_pw_head, &l2vpn->pw_tree) { if (af != pw->af || ldp_addrcmp(af, &pw->addr, addr)) continue; @@ -438,7 +443,7 @@ l2vpn_pw_ctl(pid_t pid) static struct ctl_pw pwctl; RB_FOREACH(l2vpn, l2vpn_head, &ldeconf->l2vpn_tree) - LIST_FOREACH(pw, &l2vpn->pw_list, entry) { + RB_FOREACH(pw, l2vpn_pw_head, &l2vpn->pw_tree) { memset(&pwctl, 0, sizeof(pwctl)); strlcpy(pwctl.l2vpn_name, pw->l2vpn->name, sizeof(pwctl.l2vpn_name)); @@ -517,7 +522,7 @@ ldpe_l2vpn_init(struct l2vpn *l2vpn) { struct l2vpn_pw *pw; - LIST_FOREACH(pw, &l2vpn->pw_list, entry) + RB_FOREACH(pw, l2vpn_pw_head, &l2vpn->pw_tree) ldpe_l2vpn_pw_init(pw); } @@ -526,7 +531,7 @@ ldpe_l2vpn_exit(struct l2vpn *l2vpn) { struct l2vpn_pw *pw; - LIST_FOREACH(pw, &l2vpn->pw_list, entry) + RB_FOREACH(pw, l2vpn_pw_head, &l2vpn->pw_tree) ldpe_l2vpn_pw_exit(pw); } diff --git a/ldpd/lde.c b/ldpd/lde.c index 76d56010f5..78551e4d35 100644 --- a/ldpd/lde.c +++ b/ldpd/lde.c @@ -510,8 +510,8 @@ lde_dispatch_parent(struct thread *thread) memcpy(nl2vpn, imsg.data, sizeof(struct l2vpn)); RB_INIT(&nl2vpn->if_tree); - LIST_INIT(&nl2vpn->pw_list); - LIST_INIT(&nl2vpn->pw_inactive_list); + RB_INIT(&nl2vpn->pw_tree); + RB_INIT(&nl2vpn->pw_inactive_tree); RB_INSERT(l2vpn_head, &nconf->l2vpn_tree, nl2vpn); break; @@ -529,7 +529,7 @@ lde_dispatch_parent(struct thread *thread) memcpy(npw, imsg.data, sizeof(struct l2vpn_pw)); npw->l2vpn = nl2vpn; - LIST_INSERT_HEAD(&nl2vpn->pw_list, npw, entry); + RB_INSERT(l2vpn_pw_head, &nl2vpn->pw_tree, npw); break; case IMSG_RECONF_L2VPN_IPW: if ((npw = malloc(sizeof(struct l2vpn_pw))) == NULL) @@ -537,7 +537,7 @@ lde_dispatch_parent(struct thread *thread) memcpy(npw, imsg.data, sizeof(struct l2vpn_pw)); npw->l2vpn = nl2vpn; - LIST_INSERT_HEAD(&nl2vpn->pw_inactive_list, npw, entry); + RB_INSERT(l2vpn_pw_head, &nl2vpn->pw_inactive_tree, npw); break; case IMSG_RECONF_END: merge_config(ldeconf, nconf); diff --git a/ldpd/ldp_vty_conf.c b/ldpd/ldp_vty_conf.c index 317fe3f2cb..9374e37d46 100644 --- a/ldpd/ldp_vty_conf.c +++ b/ldpd/ldp_vty_conf.c @@ -358,9 +358,9 @@ ldp_l2vpn_config_write(struct vty *vty) vty_out(vty, " member interface %s%s", lif->ifname, VTY_NEWLINE); - LIST_FOREACH(pw, &l2vpn->pw_list, entry) + RB_FOREACH(pw, l2vpn_pw_head, &l2vpn->pw_tree) ldp_l2vpn_pw_config_write(vty, pw); - LIST_FOREACH(pw, &l2vpn->pw_inactive_list, entry) + RB_FOREACH(pw, l2vpn_pw_head, &l2vpn->pw_inactive_tree) ldp_l2vpn_pw_config_write(vty, pw); vty_out(vty, " !%s", VTY_NEWLINE); @@ -1425,7 +1425,7 @@ ldp_vty_l2vpn_pseudowire(struct vty *vty, struct vty_arg *args[]) if (pw == NULL) goto cancel; - LIST_REMOVE(pw, entry); + RB_REMOVE(l2vpn_pw_head, &l2vpn->pw_inactive_tree, pw); free(pw); ldp_reload(vty_conf); return (CMD_SUCCESS); @@ -1451,7 +1451,7 @@ ldp_vty_l2vpn_pseudowire(struct vty *vty, struct vty_arg *args[]) pw = l2vpn_pw_new(l2vpn, &kif); pw->flags = F_PW_STATUSTLV_CONF|F_PW_CWORD_CONF; - LIST_INSERT_HEAD(&l2vpn->pw_inactive_list, pw, entry); + RB_INSERT(l2vpn_pw_head, &l2vpn->pw_inactive_tree, pw); ldp_reload_ref(vty_conf, (void **)&pw); VTY_PUSH_CONTEXT(LDP_PSEUDOWIRE_NODE, pw); @@ -1727,12 +1727,12 @@ l2vpn_del_api(struct ldpd_conf *conf, struct l2vpn *l2vpn) RB_REMOVE(l2vpn_if_head, &l2vpn->if_tree, lif); free(lif); } - while ((pw = LIST_FIRST(&l2vpn->pw_list)) != NULL) { - LIST_REMOVE(pw, entry); + while ((pw = RB_ROOT(&l2vpn->pw_tree)) != NULL) { + RB_REMOVE(l2vpn_pw_head, &l2vpn->pw_tree, pw); free(pw); } - while ((pw = LIST_FIRST(&l2vpn->pw_inactive_list)) != NULL) { - LIST_REMOVE(pw, entry); + while ((pw = RB_ROOT(&l2vpn->pw_inactive_tree)) != NULL) { + RB_REMOVE(l2vpn_pw_head, &l2vpn->pw_inactive_tree, pw); free(pw); } RB_REMOVE(l2vpn_head, &conf->l2vpn_tree, l2vpn); @@ -1791,13 +1791,13 @@ l2vpn_pw_new_api(struct ldpd_conf *conf, struct l2vpn *l2vpn, pw = l2vpn_pw_new(l2vpn, &kif); pw->flags = F_PW_STATUSTLV_CONF|F_PW_CWORD_CONF; - LIST_INSERT_HEAD(&l2vpn->pw_inactive_list, pw, entry); + RB_INSERT(l2vpn_pw_head, &l2vpn->pw_inactive_tree, pw); return (pw); } void -l2vpn_pw_del_api(struct l2vpn_pw *pw) +l2vpn_pw_del_api(struct l2vpn *l2vpn, struct l2vpn_pw *pw) { - LIST_REMOVE(pw, entry); + RB_REMOVE(l2vpn_pw_head, &l2vpn->pw_inactive_tree, pw); free(pw); } diff --git a/ldpd/ldpd.c b/ldpd/ldpd.c index dce62801e7..227dc49f8b 100644 --- a/ldpd/ldpd.c +++ b/ldpd/ldpd.c @@ -919,12 +919,12 @@ main_imsg_send_config(struct ldpd_conf *xconf) sizeof(*lif)) == -1) return (-1); } - LIST_FOREACH(pw, &l2vpn->pw_list, entry) { + RB_FOREACH(pw, l2vpn_pw_head, &l2vpn->pw_tree) { if (main_imsg_compose_both(IMSG_RECONF_L2VPN_PW, pw, sizeof(*pw)) == -1) return (-1); } - LIST_FOREACH(pw, &l2vpn->pw_inactive_list, entry) { + RB_FOREACH(pw, l2vpn_pw_head, &l2vpn->pw_inactive_tree) { if (main_imsg_compose_both(IMSG_RECONF_L2VPN_IPW, pw, sizeof(*pw)) == -1) return (-1); @@ -972,14 +972,14 @@ ldp_config_normalize(struct ldpd_conf *xconf, void **ref) } RB_FOREACH(l2vpn, l2vpn_head, &xconf->l2vpn_tree) { - LIST_FOREACH(pw, &l2vpn->pw_list, entry) { + RB_FOREACH(pw, l2vpn_pw_head, &l2vpn->pw_tree) { if (pw->flags & F_PW_STATIC_NBR_ADDR) continue; pw->af = AF_INET; pw->addr.v4 = pw->lsr_id; } - LIST_FOREACH(pw, &l2vpn->pw_inactive_list, entry) { + RB_FOREACH(pw, l2vpn_pw_head, &l2vpn->pw_inactive_tree) { if (pw->flags & F_PW_STATIC_NBR_ADDR) continue; @@ -1095,8 +1095,8 @@ ldp_dup_config_ref(struct ldpd_conf *conf, void **ref) RB_FOREACH(l2vpn, l2vpn_head, &conf->l2vpn_tree) { COPY(xl, l2vpn); RB_INIT(&xl->if_tree); - LIST_INIT(&xl->pw_list); - LIST_INIT(&xl->pw_inactive_list); + RB_INIT(&xl->pw_tree); + RB_INIT(&xl->pw_inactive_tree); RB_INSERT(l2vpn_head, &xconf->l2vpn_tree, xl); RB_FOREACH(lif, l2vpn_if_head, &l2vpn->if_tree) { @@ -1104,15 +1104,15 @@ ldp_dup_config_ref(struct ldpd_conf *conf, void **ref) xf->l2vpn = xl; RB_INSERT(l2vpn_if_head, &xl->if_tree, xf); } - LIST_FOREACH(pw, &l2vpn->pw_list, entry) { + RB_FOREACH(pw, l2vpn_pw_head, &l2vpn->pw_tree) { COPY(xp, pw); xp->l2vpn = xl; - LIST_INSERT_HEAD(&xl->pw_list, xp, entry); + RB_INSERT(l2vpn_pw_head, &xl->pw_tree, xp); } - LIST_FOREACH(pw, &l2vpn->pw_inactive_list, entry) { + RB_FOREACH(pw, l2vpn_pw_head, &l2vpn->pw_inactive_tree) { COPY(xp, pw); xp->l2vpn = xl; - LIST_INSERT_HEAD(&xl->pw_inactive_list, xp, entry); + RB_INSERT(l2vpn_pw_head, &xl->pw_inactive_tree, xp); } } #undef COPY @@ -1525,9 +1525,9 @@ merge_l2vpns(struct ldpd_conf *conf, struct ldpd_conf *xconf, void **ref) case PROC_MAIN: RB_FOREACH(lif, l2vpn_if_head, &l2vpn->if_tree) QOBJ_UNREG (lif); - LIST_FOREACH(pw, &l2vpn->pw_list, entry) + RB_FOREACH(pw, l2vpn_pw_head, &l2vpn->pw_tree) QOBJ_UNREG (pw); - LIST_FOREACH(pw, &l2vpn->pw_inactive_list, entry) + RB_FOREACH(pw, l2vpn_pw_head, &l2vpn->pw_inactive_tree) QOBJ_UNREG (pw); QOBJ_UNREG (l2vpn); break; @@ -1571,7 +1571,7 @@ merge_l2vpn(struct ldpd_conf *xconf, struct l2vpn *l2vpn, struct l2vpn *xl, void struct l2vpn_pw *pw, *ptmp, *xp; struct nbr *nbr; int reset_nbr, reinstall_pwfec, reinstall_tnbr; - LIST_HEAD(, l2vpn_pw) pw_aux_list; + struct l2vpn_pw_head pw_aux_list; int previous_pw_type, previous_mtu; previous_pw_type = l2vpn->pw_type; @@ -1605,8 +1605,8 @@ merge_l2vpn(struct ldpd_conf *xconf, struct l2vpn *l2vpn, struct l2vpn *xl, void } /* merge active pseudowires */ - LIST_INIT(&pw_aux_list); - LIST_FOREACH_SAFE(pw, &l2vpn->pw_list, entry, ptmp) { + RB_INIT(&pw_aux_list); + RB_FOREACH_SAFE(pw, l2vpn_pw_head, &l2vpn->pw_tree, ptmp) { /* find deleted active pseudowires */ if ((xp = l2vpn_pw_find_name(xl, pw->ifname)) == NULL) { switch (ldpd_process) { @@ -1621,15 +1621,15 @@ merge_l2vpn(struct ldpd_conf *xconf, struct l2vpn *l2vpn, struct l2vpn *xl, void break; } - LIST_REMOVE(pw, entry); + RB_REMOVE(l2vpn_pw_head, &l2vpn->pw_tree, pw); free(pw); } } - LIST_FOREACH_SAFE(xp, &xl->pw_list, entry, ptmp) { + RB_FOREACH_SAFE(xp, l2vpn_pw_head, &xl->pw_tree, ptmp) { /* find new active pseudowires */ if ((pw = l2vpn_pw_find_name(l2vpn, xp->ifname)) == NULL) { - LIST_REMOVE(xp, entry); - LIST_INSERT_HEAD(&l2vpn->pw_list, xp, entry); + RB_REMOVE(l2vpn_pw_head, &xl->pw_tree, xp); + RB_INSERT(l2vpn_pw_head, &l2vpn->pw_tree, xp); xp->l2vpn = l2vpn; switch (ldpd_process) { @@ -1685,8 +1685,8 @@ merge_l2vpn(struct ldpd_conf *xconf, struct l2vpn *l2vpn, struct l2vpn *xl, void } /* remove from active list */ - LIST_REMOVE(pw, entry); - LIST_INSERT_HEAD(&pw_aux_list, pw, entry); + RB_REMOVE(l2vpn_pw_head, &l2vpn->pw_tree, pw); + RB_INSERT(l2vpn_pw_head, &pw_aux_list, pw); } if (ldpd_process == PROC_LDP_ENGINE) { @@ -1730,27 +1730,27 @@ merge_l2vpn(struct ldpd_conf *xconf, struct l2vpn *l2vpn, struct l2vpn *xl, void l2vpn->mtu = previous_mtu; } - LIST_REMOVE(xp, entry); + RB_REMOVE(l2vpn_pw_head, &xl->pw_tree, xp); if (ref && *ref == xp) *ref = pw; free(xp); } /* merge inactive pseudowires */ - LIST_FOREACH_SAFE(pw, &l2vpn->pw_inactive_list, entry, ptmp) { + RB_FOREACH_SAFE(pw, l2vpn_pw_head, &l2vpn->pw_inactive_tree, ptmp) { /* find deleted inactive pseudowires */ if ((xp = l2vpn_pw_find_name(xl, pw->ifname)) == NULL) { - LIST_REMOVE(pw, entry); + RB_REMOVE(l2vpn_pw_head, &l2vpn->pw_inactive_tree, pw); if (ldpd_process == PROC_MAIN) QOBJ_UNREG (pw); free(pw); } } - LIST_FOREACH_SAFE(xp, &xl->pw_inactive_list, entry, ptmp) { + RB_FOREACH_SAFE(xp, l2vpn_pw_head, &xl->pw_inactive_tree, ptmp) { /* find new inactive pseudowires */ if ((pw = l2vpn_pw_find_name(l2vpn, xp->ifname)) == NULL) { - LIST_REMOVE(xp, entry); - LIST_INSERT_HEAD(&l2vpn->pw_inactive_list, xp, entry); + RB_REMOVE(l2vpn_pw_head, &xl->pw_inactive_tree, xp); + RB_INSERT(l2vpn_pw_head, &l2vpn->pw_inactive_tree, xp); xp->l2vpn = l2vpn; if (ldpd_process == PROC_MAIN) QOBJ_REG (xp, l2vpn_pw); @@ -1769,8 +1769,8 @@ merge_l2vpn(struct ldpd_conf *xconf, struct l2vpn *l2vpn, struct l2vpn *xl, void /* check if the pseudowire should be activated */ if (pw->lsr_id.s_addr != INADDR_ANY && pw->pwid != 0) { /* remove from inactive list */ - LIST_REMOVE(pw, entry); - LIST_INSERT_HEAD(&l2vpn->pw_list, pw, entry); + RB_REMOVE(l2vpn_pw_head, &l2vpn->pw_inactive_tree, pw); + RB_INSERT(l2vpn_pw_head, &l2vpn->pw_tree, pw); switch (ldpd_process) { case PROC_LDE_ENGINE: @@ -1784,16 +1784,16 @@ merge_l2vpn(struct ldpd_conf *xconf, struct l2vpn *l2vpn, struct l2vpn *xl, void } } - LIST_REMOVE(xp, entry); + RB_REMOVE(l2vpn_pw_head, &xl->pw_inactive_tree, xp); if (ref && *ref == xp) *ref = pw; free(xp); } /* insert pseudowires that were disabled in the inactive list */ - LIST_FOREACH_SAFE(pw, &pw_aux_list, entry, ptmp) { - LIST_REMOVE(pw, entry); - LIST_INSERT_HEAD(&l2vpn->pw_inactive_list, pw, entry); + RB_FOREACH_SAFE(pw, l2vpn_pw_head, &pw_aux_list, ptmp) { + RB_REMOVE(l2vpn_pw_head, &l2vpn->pw_tree, pw); + RB_INSERT(l2vpn_pw_head, &l2vpn->pw_inactive_tree, pw); } l2vpn->pw_type = xl->pw_type; diff --git a/ldpd/ldpd.h b/ldpd/ldpd.h index 9bda8ed218..79af31d805 100644 --- a/ldpd/ldpd.h +++ b/ldpd/ldpd.h @@ -337,7 +337,7 @@ RB_PROTOTYPE(l2vpn_if_head, l2vpn_if, entry, l2vpn_if_compare); DECLARE_QOBJ_TYPE(l2vpn_if) struct l2vpn_pw { - LIST_ENTRY(l2vpn_pw) entry; + RB_ENTRY(l2vpn_pw) entry; struct l2vpn *l2vpn; struct in_addr lsr_id; int af; @@ -351,6 +351,8 @@ struct l2vpn_pw { uint8_t flags; QOBJ_FIELDS }; +RB_HEAD(l2vpn_pw_head, l2vpn_pw); +RB_PROTOTYPE(l2vpn_pw_head, l2vpn_pw, entry, l2vpn_pw_compare); DECLARE_QOBJ_TYPE(l2vpn_pw) #define F_PW_STATUSTLV_CONF 0x01 /* status tlv configured */ #define F_PW_STATUSTLV 0x02 /* status tlv negotiated */ @@ -368,8 +370,8 @@ struct l2vpn { char br_ifname[IF_NAMESIZE]; unsigned int br_ifindex; struct l2vpn_if_head if_tree; - LIST_HEAD(, l2vpn_pw) pw_list; - LIST_HEAD(, l2vpn_pw) pw_inactive_list; + struct l2vpn_pw_head pw_tree; + struct l2vpn_pw_head pw_inactive_tree; QOBJ_FIELDS }; RB_HEAD(l2vpn_head, l2vpn); @@ -657,7 +659,8 @@ void l2vpn_if_del_api(struct l2vpn *l2vpn, struct l2vpn_if *lif); struct l2vpn_pw *l2vpn_pw_new_api(struct ldpd_conf *conf, struct l2vpn *l2vpn, const char *ifname); -void l2vpn_pw_del_api(struct l2vpn_pw *pw); +void l2vpn_pw_del_api(struct l2vpn *l2vpn, + struct l2vpn_pw *pw); /* socket.c */ int ldp_create_socket(int, enum socket_type); diff --git a/ldpd/ldpe.c b/ldpd/ldpe.c index 103a1ec412..9a03410069 100644 --- a/ldpd/ldpe.c +++ b/ldpd/ldpe.c @@ -453,8 +453,8 @@ ldpe_dispatch_main(struct thread *thread) memcpy(nl2vpn, imsg.data, sizeof(struct l2vpn)); RB_INIT(&nl2vpn->if_tree); - LIST_INIT(&nl2vpn->pw_list); - LIST_INIT(&nl2vpn->pw_inactive_list); + RB_INIT(&nl2vpn->pw_tree); + RB_INIT(&nl2vpn->pw_inactive_tree); RB_INSERT(l2vpn_head, &nconf->l2vpn_tree, nl2vpn); break; @@ -472,7 +472,7 @@ ldpe_dispatch_main(struct thread *thread) memcpy(npw, imsg.data, sizeof(struct l2vpn_pw)); npw->l2vpn = nl2vpn; - LIST_INSERT_HEAD(&nl2vpn->pw_list, npw, entry); + RB_INSERT(l2vpn_pw_head, &nl2vpn->pw_tree, npw); break; case IMSG_RECONF_L2VPN_IPW: if ((npw = malloc(sizeof(struct l2vpn_pw))) == NULL) @@ -480,7 +480,7 @@ ldpe_dispatch_main(struct thread *thread) memcpy(npw, imsg.data, sizeof(struct l2vpn_pw)); npw->l2vpn = nl2vpn; - LIST_INSERT_HEAD(&nl2vpn->pw_inactive_list, npw, entry); + RB_INSERT(l2vpn_pw_head, &nl2vpn->pw_inactive_tree, npw); break; case IMSG_RECONF_END: merge_config(leconf, nconf); From 0ba645b91ddbe63cc607069b2a59e50f674f118e Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Wed, 14 Dec 2016 17:39:28 -0200 Subject: [PATCH 19/27] ldpd: use red-black trees to store 'adj' elements Using red-black trees instead of linked lists brings the following benefits: 1 - Elements are naturally ordered (no need to reorder anything before outputting data to the user); 2 - Faster lookups/deletes: O(log n) time complexity against O(n). The insert operation with red-black trees is more expensive though, but that's not a big issue since lookups are much more frequent. Signed-off-by: Renato Westphal --- ldpd/adjacency.c | 70 +++++++++++++++++++++++++++++------------------- ldpd/hello.c | 2 +- ldpd/interface.c | 8 +++--- ldpd/lde.c | 4 +-- ldpd/ldpd.h | 9 ++++--- ldpd/ldpe.c | 18 ++++++------- ldpd/ldpe.h | 12 ++++++--- ldpd/neighbor.c | 10 +++---- 8 files changed, 78 insertions(+), 55 deletions(-) diff --git a/ldpd/adjacency.c b/ldpd/adjacency.c index f01f7a12fa..69031bdd75 100644 --- a/ldpd/adjacency.c +++ b/ldpd/adjacency.c @@ -25,6 +25,7 @@ #include "ldpe.h" #include "log.h" +static __inline int adj_compare(struct adj *, struct adj *); static int adj_itimer(struct thread *); static __inline int tnbr_compare(struct tnbr *, struct tnbr *); static void tnbr_del(struct ldpd_conf *, struct tnbr *); @@ -32,8 +33,41 @@ static int tnbr_hello_timer(struct thread *); static void tnbr_start_hello_timer(struct tnbr *); static void tnbr_stop_hello_timer(struct tnbr *); +RB_GENERATE(global_adj_head, adj, global_entry, adj_compare) +RB_GENERATE(nbr_adj_head, adj, nbr_entry, adj_compare) +RB_GENERATE(ia_adj_head, adj, ia_entry, adj_compare) RB_GENERATE(tnbr_head, tnbr, entry, tnbr_compare) +static __inline int +adj_compare(struct adj *a, struct adj *b) +{ + if (a->source.type < b->source.type) + return (-1); + if (a->source.type > b->source.type) + return (1); + + switch (a->source.type) { + case HELLO_LINK: + if (a->source.link.ia->af < b->source.link.ia->af) + return (-1); + if (a->source.link.ia->af > b->source.link.ia->af) + return (1); + return (ldp_addrcmp(a->source.link.ia->af, + &a->source.link.src_addr, &b->source.link.src_addr)); + case HELLO_TARGETED: + if (a->source.target->af < b->source.target->af) + return (-1); + if (a->source.target->af > b->source.target->af) + return (1); + return (ldp_addrcmp(a->source.target->af, + &a->source.target->addr, &b->source.target->addr)); + default: + fatalx("adj_get_af: unknown hello type"); + } + + return (0); +} + struct adj * adj_new(struct in_addr lsr_id, struct hello_source *source, union ldpd_addr *addr) @@ -51,11 +85,11 @@ adj_new(struct in_addr lsr_id, struct hello_source *source, adj->source = *source; adj->trans_addr = *addr; - LIST_INSERT_HEAD(&global.adj_list, adj, global_entry); + RB_INSERT(global_adj_head, &global.adj_tree, adj); switch (source->type) { case HELLO_LINK: - LIST_INSERT_HEAD(&source->link.ia->adj_list, adj, ia_entry); + RB_INSERT(ia_adj_head, &source->link.ia->adj_tree, adj); break; case HELLO_TARGETED: source->target->adj = adj; @@ -73,12 +107,12 @@ adj_del_single(struct adj *adj) adj_stop_itimer(adj); - LIST_REMOVE(adj, global_entry); + RB_REMOVE(global_adj_head, &global.adj_tree, adj); if (adj->nbr) - LIST_REMOVE(adj, nbr_entry); + RB_REMOVE(nbr_adj_head, &adj->nbr->adj_tree, adj); switch (adj->source.type) { case HELLO_LINK: - LIST_REMOVE(adj, ia_entry); + RB_REMOVE(ia_adj_head, &adj->source.link.ia->adj_tree, adj); break; case HELLO_TARGETED: adj->source.target->adj = NULL; @@ -102,7 +136,7 @@ adj_del(struct adj *adj, uint32_t notif_status) * then delete it. */ if (nbr && nbr_adj_count(nbr, nbr->af) == 0) { - LIST_FOREACH_SAFE(adj, &nbr->adj_list, nbr_entry, atmp) + RB_FOREACH_SAFE(adj, nbr_adj_head, &nbr->adj_tree, atmp) adj_del_single(adj); session_shutdown(nbr, notif_status, 0, 0); nbr_del(nbr); @@ -112,27 +146,9 @@ adj_del(struct adj *adj, uint32_t notif_status) struct adj * adj_find(struct hello_source *source) { - struct adj *adj; - - LIST_FOREACH(adj, &global.adj_list, global_entry) { - if (adj->source.type != source->type) - continue; - - switch (source->type) { - case HELLO_LINK: - if (ldp_addrcmp(source->link.ia->af, - &adj->source.link.src_addr, - &source->link.src_addr) == 0) - return (adj); - break; - case HELLO_TARGETED: - if (adj->source.target == source->target) - return (adj); - break; - } - } - - return (NULL); + struct adj adj; + adj.source = *source; + return (RB_FIND(global_adj_head, &global.adj_tree, &adj)); } int diff --git a/ldpd/hello.c b/ldpd/hello.c index 0833ebbafb..95be1d5111 100644 --- a/ldpd/hello.c +++ b/ldpd/hello.c @@ -364,7 +364,7 @@ recv_hello(struct in_addr lsr_id, struct ldp_msg *msg, int af, adj = adj_new(lsr_id, &source, &trans_addr); if (nbr) { adj->nbr = nbr; - LIST_INSERT_HEAD(&nbr->adj_list, adj, nbr_entry); + RB_INSERT(nbr_adj_head, &nbr->adj_tree, adj); } } diff --git a/ldpd/interface.c b/ldpd/interface.c index 06d36fef72..8fea91b878 100644 --- a/ldpd/interface.c +++ b/ldpd/interface.c @@ -66,14 +66,14 @@ if_new(struct kif *kif) iface->ipv4.iface = iface; iface->ipv4.enabled = 0; iface->ipv4.state = IF_STA_DOWN; - LIST_INIT(&iface->ipv4.adj_list); + RB_INIT(&iface->ipv4.adj_tree); /* ipv6 */ iface->ipv6.af = AF_INET6; iface->ipv6.iface = iface; iface->ipv6.enabled = 0; iface->ipv6.state = IF_STA_DOWN; - LIST_INIT(&iface->ipv6.adj_list); + RB_INIT(&iface->ipv6.adj_tree); return (iface); } @@ -293,7 +293,7 @@ if_reset(struct iface *iface, int af) ia = iface_af_get(iface, af); if_stop_hello_timer(ia); - while ((adj = LIST_FIRST(&ia->adj_list)) != NULL) + while ((adj = RB_ROOT(&ia->adj_tree)) != NULL) adj_del(adj, S_SHUTDOWN); /* try to cleanup */ @@ -465,7 +465,7 @@ if_to_ctl(struct iface_af *ia) ictl.uptime = 0; ictl.adj_cnt = 0; - LIST_FOREACH(adj, &ia->adj_list, ia_entry) + RB_FOREACH(adj, ia_adj_head, &ia->adj_tree) ictl.adj_cnt++; return (&ictl); diff --git a/ldpd/lde.c b/ldpd/lde.c index 78551e4d35..b19418585e 100644 --- a/ldpd/lde.c +++ b/ldpd/lde.c @@ -483,8 +483,8 @@ lde_dispatch_parent(struct thread *thread) memcpy(niface, imsg.data, sizeof(struct iface)); LIST_INIT(&niface->addr_list); - LIST_INIT(&niface->ipv4.adj_list); - LIST_INIT(&niface->ipv6.adj_list); + RB_INIT(&niface->ipv4.adj_tree); + RB_INIT(&niface->ipv6.adj_tree); niface->ipv4.iface = niface; niface->ipv6.iface = niface; diff --git a/ldpd/ldpd.h b/ldpd/ldpd.h index 79af31d805..bfce014b9b 100644 --- a/ldpd/ldpd.h +++ b/ldpd/ldpd.h @@ -196,7 +196,10 @@ enum nbr_action { NBR_ACT_CLOSE_SESSION }; -TAILQ_HEAD(mapping_head, mapping_entry); +/* forward declarations */ +RB_HEAD(global_adj_head, adj); +RB_HEAD(nbr_adj_head, adj); +RB_HEAD(ia_adj_head, adj); struct map { uint8_t type; @@ -256,7 +259,7 @@ struct iface_af { int af; int enabled; int state; - LIST_HEAD(, adj) adj_list; + struct ia_adj_head adj_tree; time_t uptime; struct thread *hello_timer; uint16_t hello_holdtime; @@ -450,7 +453,7 @@ struct ldpd_global { uint32_t conf_seqnum; int pfkeysock; struct if_addr_head addr_list; - LIST_HEAD(, adj) adj_list; + struct global_adj_head adj_tree; struct in_addr mcast_addr_v4; struct in6_addr mcast_addr_v6; TAILQ_HEAD(, pending_conn) pending_conns; diff --git a/ldpd/ldpe.c b/ldpd/ldpe.c index 9a03410069..798085b935 100644 --- a/ldpd/ldpe.c +++ b/ldpd/ldpe.c @@ -111,7 +111,7 @@ ldpe(const char *user, const char *group, const char *ctl_path) ldpd_process = PROC_LDP_ENGINE; LIST_INIT(&global.addr_list); - LIST_INIT(&global.adj_list); + RB_INIT(&global.adj_tree); TAILQ_INIT(&global.pending_conns); if (inet_pton(AF_INET, AllRouters_v4, &global.mcast_addr_v4) != 1) fatal("inet_pton"); @@ -210,7 +210,7 @@ ldpe_shutdown(void) LIST_REMOVE(if_addr, entry); free(if_addr); } - while ((adj = LIST_FIRST(&global.adj_list)) != NULL) + while ((adj = RB_ROOT(&global.adj_tree)) != NULL) adj_del(adj, S_SHUTDOWN); /* clean up */ @@ -426,8 +426,8 @@ ldpe_dispatch_main(struct thread *thread) memcpy(niface, imsg.data, sizeof(struct iface)); LIST_INIT(&niface->addr_list); - LIST_INIT(&niface->ipv4.adj_list); - LIST_INIT(&niface->ipv6.adj_list); + RB_INIT(&niface->ipv4.adj_tree); + RB_INIT(&niface->ipv6.adj_tree); niface->ipv4.iface = niface; niface->ipv6.iface = niface; @@ -815,18 +815,18 @@ ldpe_adj_ctl(struct ctl_conn *c) continue; strlcpy(ictl.name, iface->name, sizeof(ictl.name)); - if (LIST_EMPTY(&iface->ipv4.adj_list) && - LIST_EMPTY(&iface->ipv6.adj_list)) + if (RB_EMPTY(&iface->ipv4.adj_tree) && + RB_EMPTY(&iface->ipv6.adj_tree)) ictl.no_adj = 1; imsg_compose_event(&c->iev, IMSG_CTL_SHOW_DISC_IFACE, 0, 0, -1, &ictl, sizeof(ictl)); - LIST_FOREACH(adj, &iface->ipv4.adj_list, ia_entry) { + RB_FOREACH(adj, ia_adj_head, &iface->ipv4.adj_tree) { actl = adj_to_ctl(adj); imsg_compose_event(&c->iev, IMSG_CTL_SHOW_DISC_ADJ, 0, 0, -1, actl, sizeof(struct ctl_adj)); } - LIST_FOREACH(adj, &iface->ipv6.adj_list, ia_entry) { + RB_FOREACH(adj, ia_adj_head, &iface->ipv6.adj_tree) { actl = adj_to_ctl(adj); imsg_compose_event(&c->iev, IMSG_CTL_SHOW_DISC_ADJ, 0, 0, -1, actl, sizeof(struct ctl_adj)); @@ -870,7 +870,7 @@ ldpe_nbr_ctl(struct ctl_conn *c) imsg_compose_event(&c->iev, IMSG_CTL_SHOW_NBR, 0, 0, -1, nctl, sizeof(struct ctl_nbr)); - LIST_FOREACH(adj, &nbr->adj_list, nbr_entry) { + RB_FOREACH(adj, nbr_adj_head, &nbr->adj_tree) { actl = adj_to_ctl(adj); imsg_compose_event(&c->iev, IMSG_CTL_SHOW_NBR_DISC, 0, 0, -1, actl, sizeof(struct ctl_adj)); diff --git a/ldpd/ldpe.h b/ldpd/ldpe.h index a57727591a..6a2f4b3cf5 100644 --- a/ldpd/ldpe.h +++ b/ldpd/ldpe.h @@ -32,6 +32,9 @@ #define min(x,y) ((x) <= (y) ? (x) : (y)) #define max(x,y) ((x) > (y) ? (x) : (y)) +/* forward declarations */ +TAILQ_HEAD(mapping_head, mapping_entry); + struct hello_source { enum hello_type type; struct { @@ -42,9 +45,7 @@ struct hello_source { }; struct adj { - LIST_ENTRY(adj) global_entry; - LIST_ENTRY(adj) nbr_entry; - LIST_ENTRY(adj) ia_entry; + RB_ENTRY(adj) global_entry, nbr_entry, ia_entry; struct in_addr lsr_id; struct nbr *nbr; int ds_tlv; @@ -53,6 +54,9 @@ struct adj { uint16_t holdtime; union ldpd_addr trans_addr; }; +RB_PROTOTYPE(global_adj_head, adj, global_entry, adj_compare) +RB_PROTOTYPE(nbr_adj_head, adj, nbr_entry, adj_compare) +RB_PROTOTYPE(ia_adj_head, adj, ia_entry, adj_compare) struct tcp_conn { struct nbr *nbr; @@ -67,7 +71,7 @@ struct tcp_conn { struct nbr { RB_ENTRY(nbr) id_tree, addr_tree, pid_tree; struct tcp_conn *tcp; - LIST_HEAD(, adj) adj_list; /* adjacencies */ + struct nbr_adj_head adj_tree; /* adjacencies */ struct thread *ev_connect; struct thread *keepalive_timer; struct thread *keepalive_timeout; diff --git a/ldpd/neighbor.c b/ldpd/neighbor.c index 5addc4dda2..d24ceb1229 100644 --- a/ldpd/neighbor.c +++ b/ldpd/neighbor.c @@ -229,7 +229,7 @@ nbr_new(struct in_addr id, int af, int ds_tlv, union ldpd_addr *addr, if ((nbr = calloc(1, sizeof(*nbr))) == NULL) fatal(__func__); - LIST_INIT(&nbr->adj_list); + RB_INIT(&nbr->adj_tree); nbr->state = NBR_STA_PRESENT; nbr->peerid = 0; nbr->af = af; @@ -244,10 +244,10 @@ nbr_new(struct in_addr id, int af, int ds_tlv, union ldpd_addr *addr, nbr->raddr_scope = scope_id; nbr->conf_seqnum = 0; - LIST_FOREACH(adj, &global.adj_list, global_entry) { + RB_FOREACH(adj, global_adj_head, &global.adj_tree) { if (adj->lsr_id.s_addr == nbr->id.s_addr) { adj->nbr = nbr; - LIST_INSERT_HEAD(&nbr->adj_list, adj, nbr_entry); + RB_INSERT(nbr_adj_head, &nbr->adj_tree, adj); } } @@ -366,7 +366,7 @@ nbr_adj_count(struct nbr *nbr, int af) struct adj *adj; int total = 0; - LIST_FOREACH(adj, &nbr->adj_list, nbr_entry) + RB_FOREACH(adj, nbr_adj_head, &nbr->adj_tree) if (adj_get_af(adj) == af) total++; @@ -624,7 +624,7 @@ nbr_establish_connection(struct nbr *nbr) * Send an extra hello to guarantee that the remote peer has formed * an adjacency as well. */ - LIST_FOREACH(adj, &nbr->adj_list, nbr_entry) + RB_FOREACH(adj, nbr_adj_head, &nbr->adj_tree) send_hello(adj->source.type, adj->source.link.ia, adj->source.target); From f4dbf917b9f49ba048ed05a615d7a364cfecf9fd Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Tue, 13 Dec 2016 22:51:41 -0200 Subject: [PATCH 20/27] ldpd: fix segfault when configuring multiple pseudowires Signed-off-by: Renato Westphal --- ldpd/ldp_vty_conf.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/ldpd/ldp_vty_conf.c b/ldpd/ldp_vty_conf.c index 9374e37d46..8b5f3cafa1 100644 --- a/ldpd/ldp_vty_conf.c +++ b/ldpd/ldp_vty_conf.c @@ -1250,7 +1250,7 @@ ldp_vty_l2vpn(struct vty *vty, struct vty_arg *args[]) l2vpn->type = L2VPN_TYPE_VPLS; RB_INSERT(l2vpn_head, &vty_conf->l2vpn_tree, l2vpn); - ldp_reload(vty_conf); + ldp_reload_ref(vty_conf, (void **)&l2vpn); VTY_PUSH_CONTEXT(LDP_L2VPN_NODE, l2vpn); return (CMD_SUCCESS); @@ -1432,7 +1432,7 @@ ldp_vty_l2vpn_pseudowire(struct vty *vty, struct vty_arg *args[]) } if (pw) { - VTY_PUSH_CONTEXT(LDP_PSEUDOWIRE_NODE, pw); + VTY_PUSH_CONTEXT_SUB(LDP_PSEUDOWIRE_NODE, pw); goto cancel; } @@ -1454,7 +1454,7 @@ ldp_vty_l2vpn_pseudowire(struct vty *vty, struct vty_arg *args[]) RB_INSERT(l2vpn_pw_head, &l2vpn->pw_inactive_tree, pw); ldp_reload_ref(vty_conf, (void **)&pw); - VTY_PUSH_CONTEXT(LDP_PSEUDOWIRE_NODE, pw); + VTY_PUSH_CONTEXT_SUB(LDP_PSEUDOWIRE_NODE, pw); return (CMD_SUCCESS); @@ -1474,7 +1474,7 @@ ldp_vty_l2vpn_pw_cword(struct vty *vty, struct vty_arg *args[]) disable = (vty_get_arg_value(args, "no")) ? 1 : 0; preference_str = vty_get_arg_value(args, "preference"); - pw = VTY_GET_CONTEXT(l2vpn_pw); + pw = VTY_GET_CONTEXT_SUB(l2vpn_pw); vty_conf = ldp_dup_config_ref(ldpd_conf, (void **)&pw); if (disable) @@ -1510,7 +1510,7 @@ ldp_vty_l2vpn_pw_nbr_addr(struct vty *vty, struct vty_arg *args[]) return (CMD_WARNING); } - pw = VTY_GET_CONTEXT(l2vpn_pw); + pw = VTY_GET_CONTEXT_SUB(l2vpn_pw); vty_conf = ldp_dup_config_ref(ldpd_conf, (void **)&pw); if (disable) { @@ -1546,7 +1546,7 @@ ldp_vty_l2vpn_pw_nbr_id(struct vty *vty, struct vty_arg *args[]) return (CMD_WARNING); } - pw = VTY_GET_CONTEXT(l2vpn_pw); + pw = VTY_GET_CONTEXT_SUB(l2vpn_pw); vty_conf = ldp_dup_config_ref(ldpd_conf, (void **)&pw); if (disable) @@ -1578,7 +1578,7 @@ ldp_vty_l2vpn_pw_pwid(struct vty *vty, struct vty_arg *args[]) return (CMD_WARNING); } - pw = VTY_GET_CONTEXT(l2vpn_pw); + pw = VTY_GET_CONTEXT_SUB(l2vpn_pw); vty_conf = ldp_dup_config_ref(ldpd_conf, (void **)&pw); if (disable) @@ -1600,7 +1600,7 @@ ldp_vty_l2vpn_pw_pwstatus(struct vty *vty, struct vty_arg *args[]) disable = (vty_get_arg_value(args, "no")) ? 1 : 0; - pw = VTY_GET_CONTEXT(l2vpn_pw); + pw = VTY_GET_CONTEXT_SUB(l2vpn_pw); vty_conf = ldp_dup_config_ref(ldpd_conf, (void **)&pw); if (disable) From 278fb111f6a2ee693c55335f4fa93e548df42091 Mon Sep 17 00:00:00 2001 From: Martin Winter Date: Thu, 16 Feb 2017 16:40:09 +0700 Subject: [PATCH 21/27] doc: Add initial set of docs on building FRR on various Distributions Signed-off-by: Martin Winter --- README | 12 ++- doc/Building_FRR_on_CentOS6.md | 153 ++++++++++++++++++++++++++++++ doc/Building_FRR_on_CentOS7.md | 119 +++++++++++++++++++++++ doc/Building_FRR_on_Debian8.md | 94 ++++++++++++++++++ doc/Building_FRR_on_Fedora24.md | 129 +++++++++++++++++++++++++ doc/Building_FRR_on_FreeBSD10.md | 91 ++++++++++++++++++ doc/Building_FRR_on_FreeBSD11.md | 91 ++++++++++++++++++ doc/Building_FRR_on_FreeBSD9.md | 91 ++++++++++++++++++ doc/Building_FRR_on_NetBSD6.md | 116 ++++++++++++++++++++++ doc/Building_FRR_on_NetBSD7.md | 109 +++++++++++++++++++++ doc/Building_FRR_on_OmniOS.md | 120 +++++++++++++++++++++++ doc/Building_FRR_on_OpenBSD6.md | 126 ++++++++++++++++++++++++ doc/Building_FRR_on_Ubuntu1204.md | 128 +++++++++++++++++++++++++ doc/Building_FRR_on_Ubuntu1404.md | 88 +++++++++++++++++ doc/Building_FRR_on_Ubuntu1604.md | 111 ++++++++++++++++++++++ 15 files changed, 1574 insertions(+), 4 deletions(-) create mode 100644 doc/Building_FRR_on_CentOS6.md create mode 100644 doc/Building_FRR_on_CentOS7.md create mode 100644 doc/Building_FRR_on_Debian8.md create mode 100644 doc/Building_FRR_on_Fedora24.md create mode 100644 doc/Building_FRR_on_FreeBSD10.md create mode 100644 doc/Building_FRR_on_FreeBSD11.md create mode 100644 doc/Building_FRR_on_FreeBSD9.md create mode 100644 doc/Building_FRR_on_NetBSD6.md create mode 100644 doc/Building_FRR_on_NetBSD7.md create mode 100644 doc/Building_FRR_on_OmniOS.md create mode 100644 doc/Building_FRR_on_OpenBSD6.md create mode 100644 doc/Building_FRR_on_Ubuntu1204.md create mode 100644 doc/Building_FRR_on_Ubuntu1404.md create mode 100644 doc/Building_FRR_on_Ubuntu1604.md diff --git a/README b/README index 4476947490..18bb94e4a5 100644 --- a/README +++ b/README @@ -1,9 +1,13 @@ -Quagga is free software that manages various IPv4 and IPv6 routing +FRR is a free fork of Quagga that manages various IPv4 and IPv6 routing protocols. -Currently Quagga supports BGP4, BGP4+, OSPFv2, OSPFv3, RIPv1, -RIPv2, RIPng, PIM-SSM and LDP as well as very early support for IS-IS. +Currently FRR supports BGP4, BGP4+, OSPFv2, OSPFv3, IS-IS, RIPv1, +RIPv2, RIPng, PIM-SSM and LDP. See the file REPORTING-BUGS to report bugs. -Quagga is free software. See the file COPYING for copying conditions. +FRR is free software. See the file COPYING for copying conditions. + +For building instructions from the source, see doc/Building_FRR_on_*.md +documents. + diff --git a/doc/Building_FRR_on_CentOS6.md b/doc/Building_FRR_on_CentOS6.md new file mode 100644 index 0000000000..f770aebcf5 --- /dev/null +++ b/doc/Building_FRR_on_CentOS6.md @@ -0,0 +1,153 @@ +Building FRR on CentOS 6 from Git Source +======================================== + +Instructions are tested with `CentOS 6.8` on `x86_64` platform + +CentOS 6 restrictions: +---------------------- + +- PIMd is not supported on `CentOS 6`. Upgrade to `CentOS 7` if PIMd is needed +- MPLS is not supported on `CentOS 6`. MPLS requires Linux Kernel 4.5 or higher + (LDP can be built, but may have limited use without MPLS) + +Install required packages +------------------------- + +Add packages: + + sudo yum install git autoconf automake libtool make gawk readline-devel \ + texinfo net-snmp-devel groff pkgconfig json-c-devel pam-devel \ + flex pytest + +Install newer version of bison (CentOS 6 package source is too old) from CentOS 7 + + curl -O http://vault.centos.org/7.0.1406/os/Source/SPackages/bison-2.7-4.el7.src.rpm + rpmbuild --rebuild ./bison-2.7-4.el7.src.rpm + sudo yum install ./rpmbuild/RPMS/x86_64/bison-2.7-4.el6.x86_64.rpm + rm -rf rpmbuild + +Install newer version of autoconf and automake (Package versions are too old) + + curl -O http://ftp.gnu.org/gnu/autoconf/autoconf-2.69.tar.gz + tar xvf autoconf-2.69.tar.gz + cd autoconf-2.69 + ./configure --prefix=/usr + make + sudo make install + cd .. + + curl -O http://ftp.gnu.org/gnu/automake/automake-1.15.tar.gz + tar xvf automake-1.15.tar.gz + cd automake-1.15 + ./configure --prefix=/usr + make + sudo make install + cd .. + +Install `Python 2.7` in parallel to default 2.6 (needed for `make check` to run unittests). +Pick correct EPEL based on CentOS version used. Then install current `pytest` + + rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm + rpm -ivh https://centos6.iuscommunity.org/ius-release.rpm + yum install python27 python27-pip + pip2.7 install pytest + +Please note that `CentOS 6` needs to keep python pointing to version 2.6 for `yum` to keep +working, so don't create a symlink for python2.7 to python + +Get FRR, compile it and install it (from Git) +--------------------------------------------- + +**This assumes you want to build and install FRR from source and not using any packages** + +### Add frr groups and user + + sudo groupadd -g 92 frr + sudo groupadd -r -g 85 frrvt + sudo useradd -u 92 -g 92 -M -r -G frrvt -s /sbin/nologin \ + -c "FRR FreeRangeRouting suite" -d /var/run/frr frr + +### Download Source, configure and compile it +(You may prefer different options on configure statement. These are just an example.) + +You may want to pay special attention to `/usr/lib64` paths and change them if you are not building on a x86_64 architecture + + git clone https://github.com/freerangerouting/frr.git frr + cd frr + git checkout stable/2.0 + ./bootstrap.sh + ./configure \ + --sysconfdir=/etc/frr \ + --libdir=/usr/lib64/frr \ + --libexecdir=/usr/lib64/frr \ + --localstatedir=/var/run/frr \ + --disable-pimd \ + --enable-snmp=agentx \ + --enable-multipath=64 \ + --enable-ospfclient=yes \ + --enable-ospfapi=yes \ + --enable-user=frr \ + --enable-group=frr \ + --enable-vty-group=frrvt \ + --enable-rtadv \ + --disable-exampledir \ + --enable-watchfrr \ + --enable-tcp-zebra \ + --enable-fpm \ + --with-pkg-git-version \ + --with-pkg-extra-version=-MyOwnFRRVersion + make + make check PYTHON=/usr/bin/python2.7 + sudo make install + +### Create empty FRR configuration files + sudo mkdir /var/log/frr + sudo mkdir /etc/frr + sudo touch /etc/frr/zebra.conf + sudo touch /etc/frr/bgpd.conf + sudo touch /etc/frr/ospfd.conf + sudo touch /etc/frr/ospf6d.conf + sudo touch /etc/frr/isisd.conf + sudo touch /etc/frr/ripd.conf + sudo touch /etc/frr/ripngd.conf + sudo chown -R frr:frr /etc/frr/ + sudo touch /etc/frr/vtysh.conf + sudo chown frr:frrvt /etc/frr/vtysh.conf + sudo chmod 640 /etc/frr/*.conf + +### Enable IP & IPv6 forwarding + +Edit `/etc/sysctl.conf` and set the following values (ignore the other settings) + + # Controls IP packet forwarding + net.ipv4.ip_forward = 1 + net.ipv6.conf.all.forwarding=1 + + # Controls source route verification + net.ipv4.conf.default.rp_filter = 0 + +**Reboot** or use `sysctl` to apply the same config to the running system + +### Add init.d startup files + sudo cp redhat/bgpd.init /etc/init.d/bgpd + sudo cp redhat/isisd.init /etc/init.d/isisd + sudo cp redhat/ospfd.init /etc/init.d/ospfd + sudo cp redhat/ospf6d.init /etc/init.d/ospf6d + sudo cp redhat/ripngd.init /etc/init.d/ripngd + sudo cp redhat/ripd.init /etc/init.d/ripd + sudo cp redhat/zebra.init /etc/init.d/zebra + sudo chkconfig --add zebra + sudo chkconfig --add ripd + sudo chkconfig --add ripngd + sudo chkconfig --add ospf6d + sudo chkconfig --add ospfd + sudo chkconfig --add bgpd + sudo chkconfig --add isisd + +### Enable required daemons at startup +Only enable zebra and the daemons which are needed for your setup + + sudo chkconfig zebra on + sudo chkconfig ospfd on + sudo chkconfig bgpd on + [...] etc (as needed) diff --git a/doc/Building_FRR_on_CentOS7.md b/doc/Building_FRR_on_CentOS7.md new file mode 100644 index 0000000000..36e50e4429 --- /dev/null +++ b/doc/Building_FRR_on_CentOS7.md @@ -0,0 +1,119 @@ +Building FRR on CentOS 7 from Git Source +======================================== + +CentOS 7 restrictions: +---------------------- + +- MPLS is not supported on `CentOS 7` with default kernel. MPLS requires + Linux Kernel 4.5 or higher (LDP can be built, but may have limited use + without MPLS) + +Install required packages +------------------------- + +Add packages: + + sudo yum install git autoconf automake libtool make gawk readline-devel \ + texinfo net-snmp-devel groff pkgconfig json-c-devel pam-devel \ + bison flex pytest + +Get FRR, compile it and install it (from Git) +--------------------------------------------- + +**This assumes you want to build and install FRR from source and not using any packages** + +### Add frr groups and user + + sudo groupadd -g 92 frr + sudo groupadd -r -g 85 frrvt + sudo useradd -u 92 -g 92 -M -r -G frrvt -s /sbin/nologin \ + -c "FRR FreeRangeRouting suite" -d /var/run/frr frr + +### Download Source, configure and compile it +(You may prefer different options on configure statement. These are just an example.) + +You may want to pay special attention to `/usr/lib64` paths and change them if you are not building on a x86_64 architecture + + git clone https://github.com/freerangerouting/frr.git frr + cd frr + git checkout stable/2.0 + ./bootstrap.sh + ./configure \ + --sysconfdir=/etc/frr \ + --libdir=/usr/lib64/frr \ + --libexecdir=/usr/lib64/frr \ + --localstatedir=/var/run/frr \ + --enable-snmp=agentx \ + --enable-multipath=64 \ + --enable-ospfclient=yes \ + --enable-ospfapi=yes \ + --enable-user=frr \ + --enable-group=frr \ + --enable-vty-group=frrvt \ + --enable-rtadv \ + --disable-exampledir \ + --enable-watchfrr \ + --enable-tcp-zebra \ + --enable-fpm \ + --with-pkg-git-version \ + --with-pkg-extra-version=-MyOwnFRRVersion + make + make check + sudo make install + +### Create empty FRR configuration files + sudo mkdir /var/log/frr + sudo mkdir /etc/frr + sudo touch /etc/frr/zebra.conf + sudo touch /etc/frr/bgpd.conf + sudo touch /etc/frr/ospfd.conf + sudo touch /etc/frr/ospf6d.conf + sudo touch /etc/frr/isisd.conf + sudo touch /etc/frr/ripd.conf + sudo touch /etc/frr/ripngd.conf + sudo touch /etc/frr/pimd.conf + sudo chown -R frr:frr /etc/frr/ + sudo touch /etc/frr/vtysh.conf + sudo chown frr:frrvt /etc/frr/vtysh.conf + sudo chmod 640 /etc/frr/*.conf + +### Enable IP & IPv6 forwarding + +Create a new file `/etc/sysctl.d/90-routing-sysctl.conf` with the following content: + + # Sysctl for routing + # + # Routing: We need to forward packets + net.ipv4.conf.all.forwarding=1 + net.ipv6.conf.all.forwarding=1 + +**Reboot** or use `sysctl` to apply the same config to the running system + +### Install Service files + sudo install -p -m 644 redhat/zebra.service /usr/lib/systemd/system/zebra.service + sudo install -p -m 644 redhat/isisd.service /usr/lib/systemd/system/isisd.service + sudo install -p -m 644 redhat/ripd.service /usr/lib/systemd/system/ripd.service + sudo install -p -m 644 redhat/ospfd.service /usr/lib/systemd/system/ospfd.service + sudo install -p -m 644 redhat/bgpd.service /usr/lib/systemd/system/bgpd.service + sudo install -p -m 644 redhat/ospf6d.service /usr/lib/systemd/system/ospf6d.service + sudo install -p -m 644 redhat/ripngd.service /usr/lib/systemd/system/ripngd.service + sudo install -p -m 644 redhat/pimd.service /usr/lib/systemd/system/pimd.service + sudo install -p -m 644 redhat/frr.sysconfig /etc/sysconfig/frr + sudo install -p -m 644 redhat/frr.logrotate /etc/logrotate.d/frr + +### Register the systemd files + sudo systemctl preset zebra.service + sudo systemctl preset ripd.service + sudo systemctl preset ospfd.service + sudo systemctl preset bgpd.service + sudo systemctl preset ospf6d.service + sudo systemctl preset ripngd.service + sudo systemctl preset pimd.service + +### Enable required daemons at startup +Only enable zebra and the daemons which are needed for your setup + + sudo systemctl enable zebra + sudo systemctl enable ospfd + sudo systemctl enable bgpd + [...] etc (as needed) diff --git a/doc/Building_FRR_on_Debian8.md b/doc/Building_FRR_on_Debian8.md new file mode 100644 index 0000000000..098a65d620 --- /dev/null +++ b/doc/Building_FRR_on_Debian8.md @@ -0,0 +1,94 @@ +Building FRR on Debian 8 from Git Source +======================================== + +Debian 8 restrictions: +---------------------- + +- MPLS is not supported on `Debian 8` with default kernel. MPLS requires + Linux Kernel 4.5 or higher (LDP can be built, but may have limited use + without MPLS) + +Install required packages +------------------------- + +Add packages: + + sudo apt-get install git autoconf automake libtool make gawk libreadline-dev \ + texinfo libjson-c-dev pkg-config bison flex python-pip + +Install newer pytest (>3.0) from pip + + sudo pip install pytest + +Get FRR, compile it and install it (from Git) +--------------------------------------------- + +**This assumes you want to build and install FRR from source and not using any packages** + +### Add frr groups and user + + sudo addgroup --system --gid 92 frr + sudo addgroup --system --gid 85 frrvty + sudo adduser --system --ingroup frr --groups frrvty --home /var/run/frr/ \ + --gecos "FRR FreeRangeRouting suite" --shell /bin/false frr + sudo usermode + +### Download Source, configure and compile it +(You may prefer different options on configure statement. These are just an example.) + + git clone https://github.com/freerangerouting/frr.git frr + cd frr + git checkout stable/2.0 + ./bootstrap.sh + ./configure \ + --enable-exampledir=/usr/share/doc/frr/examples/ \ + --localstatedir=/var/run/frr \ + --sbindir=/usr/lib/frr \ + --sysconfdir=/etc/frr \ + --enable-vtysh \ + --enable-isisd \ + --enable-pimd \ + --enable-watchfrr \ + --enable-ospfclient=yes \ + --enable-ospfapi=yes \ + --enable-multipath=64 \ + --enable-user=frr \ + --enable-group=frr \ + --enable-vty-group=frrvty \ + --enable-configfile-mask=0640 \ + --enable-logfile-mask=0640 \ + --enable-rtadv \ + --enable-tcp-zebra \ + --enable-fpm \ + --with-pkg-git-version \ + --with-pkg-extra-version=-MyOwnFRRVersion + make + make check + sudo make install + +### Create empty FRR configuration files + sudo install -m 755 -o frr -g frr -d /var/log/frr + sudo install -m 775 -o frr -g frrvty -d /etc/frr + sudo install -m 640 -o frr -g frr /dev/null /etc/frr/zebra.conf + sudo install -m 640 -o frr -g frr /dev/null /etc/frr/bgpd.conf + sudo install -m 640 -o frr -g frr /dev/null /etc/frr/ospfd.conf + sudo install -m 640 -o frr -g frr /dev/null /etc/frr/ospf6d.conf + sudo install -m 640 -o frr -g frr /dev/null /etc/frr/isisd.conf + sudo install -m 640 -o frr -g frr /dev/null /etc/frr/ripd.conf + sudo install -m 640 -o frr -g frr /dev/null /etc/frr/ripngd.conf + sudo install -m 640 -o frr -g frr /dev/null /etc/frr/pimd.conf + sudo install -m 640 -o frr -g frrvty /dev/null /etc/frr/vtysh.conf + +### Enable IP & IPv6 forwarding + +Edit `/etc/sysctl.conf` and uncomment the following values (ignore the other settings) + + # Uncomment the next line to enable packet forwarding for IPv4 + net.ipv4.ip_forward=1 + + # Uncomment the next line to enable packet forwarding for IPv6 + # Enabling this option disables Stateless Address Autoconfiguration + # based on Router Advertisements for this host + net.ipv6.conf.all.forwarding=1 + +**Reboot** or use `sysctl` to apply the same config to the running system diff --git a/doc/Building_FRR_on_Fedora24.md b/doc/Building_FRR_on_Fedora24.md new file mode 100644 index 0000000000..784449d736 --- /dev/null +++ b/doc/Building_FRR_on_Fedora24.md @@ -0,0 +1,129 @@ +Building FRR on Fedora 24 from Git Source +========================================= + +Install required packages +------------------------- + +Add packages: + + sudo dnf install git autoconf automake libtool make gawk readline-devel \ + texinfo net-snmp-devel groff pkgconfig json-c-devel pam-devel \ + perl-XML-LibXML pytest + +Get FRR, compile it and install it (from Git) +--------------------------------------------- + +**This assumes you want to build and install FRR from source and not using any packages** + +### Add frr groups and user + + sudo groupadd -g 92 frr + sudo groupadd -r -g 85 frrvt + sudo useradd -u 92 -g 92 -M -r -G frrvt -s /sbin/nologin \ + -c "FRR FreeRangeRouting suite" -d /var/run/frr frr + +### Download Source, configure and compile it +(You may prefer different options on configure statement. These are just an example.) + +You may want to pay special attention to `/usr/lib64` paths and chenge them if you are not building on a x86_64 architecture + + git clone https://github.com/freerangerouting/frr.git frr + cd frr + git checkout stable/2.0 + ./bootstrap.sh + ./configure \ + --sysconfdir=/etc/frr \ + --libdir=/usr/lib64/frr \ + --libexecdir=/usr/lib64/frr \ + --localstatedir=/var/run/frr \ + --enable-pimd \ + --enable-snmp=agentx \ + --enable-multipath=64 \ + --enable-ospfclient=yes \ + --enable-ospfapi=yes \ + --enable-user=frr \ + --enable-group=frr \ + --enable-vty-group=frrvt \ + --enable-rtadv \ + --disable-exampledir \ + --enable-watchfrr \ + --enable-tcp-zebra \ + --enable-fpm \ + --with-pkg-git-version \ + --with-pkg-extra-version=-MyOwnFRRVersion + make + make check + sudo make install + +### Create empty FRR configuration files + sudo mkdir /var/log/frr + sudo mkdir /etc/frr + sudo touch /etc/frr/zebra.conf + sudo touch /etc/frr/bgpd.conf + sudo touch /etc/frr/ospfd.conf + sudo touch /etc/frr/ospf6d.conf + sudo touch /etc/frr/isisd.conf + sudo touch /etc/frr/ripd.conf + sudo touch /etc/frr/ripngd.conf + sudo touch /etc/frr/pimd.conf + sudo touch /etc/frr/ldpd.conf + sudo chown -R frr:frr /etc/frr/ + sudo touch /etc/frr/vtysh.conf + sudo chown frr:frrvt /etc/frr/vtysh.conf + sudo chmod 640 /etc/frr/*.conf + +### Enable IP & IPv6 forwarding (and MPLS) + +Create a new file `/etc/sysctl.d/90-routing-sysctl.conf` with the following content: +(Please make sure to list all interfaces with required MPLS similar to `net.mpls.conf.eth0.input=1`) + + # Sysctl for routing + # + # Routing: We need to forward packets + net.ipv4.conf.all.forwarding=1 + net.ipv6.conf.all.forwarding=1 + # + # Enable MPLS Label processing on all interfaces + net.mpls.conf.eth0.input=1 + net.mpls.conf.eth1.input=1 + net.mpls.conf.eth2.input=1 + net.mpls.platform_labels=100000 + +Create a new file `/etc/modules-load.d/mpls.conf` with the following content: + + # Load MPLS Kernel Modules + mpls-router + mpls-iptunnel + +**Reboot** or use `sysctl` to apply the same config to the running system + +### Install Service files + install -p -m 644 redhat/zebra.service /usr/lib/systemd/system/zebra.service + install -p -m 644 redhat/isisd.service /usr/lib/systemd/system/isisd.service + install -p -m 644 redhat/ripd.service /usr/lib/systemd/system/ripd.service + install -p -m 644 redhat/ospfd.service /usr/lib/systemd/system/ospfd.service + install -p -m 644 redhat/bgpd.service /usr/lib/systemd/system/bgpd.service + install -p -m 644 redhat/ospf6d.service /usr/lib/systemd/system/ospf6d.service + install -p -m 644 redhat/ripngd.service /usr/lib/systemd/system/ripngd.service + install -p -m 644 redhat/pimd.service /usr/lib/systemd/system/pimd.service + install -p -m 644 redhat/pimd.service /usr/lib/systemd/system/ldpd.service + install -p -m 644 redhat/frr.sysconfig /etc/sysconfig/frr + install -p -m 644 redhat/frr.logrotate /etc/logrotate.d/frr + +### Register the systemd files + systemctl preset zebra.service + systemctl preset ripd.service + systemctl preset ospfd.service + systemctl preset bgpd.service + systemctl preset ospf6d.service + systemctl preset ripngd.service + systemctl preset pimd.service + systemctl preset ldpd.service + +### Enable required daemons at startup +Only enable zebra and the daemons which are needed for your setup + + systemctl enable zebra + systemctl enable ospfd + systemctl enable bgpd + [...] etc (as needed) diff --git a/doc/Building_FRR_on_FreeBSD10.md b/doc/Building_FRR_on_FreeBSD10.md new file mode 100644 index 0000000000..4cd0edd1a0 --- /dev/null +++ b/doc/Building_FRR_on_FreeBSD10.md @@ -0,0 +1,91 @@ +Building FRR on FreeBSD 10 from Git Source +========================================== + +FreeBSD 10 restrictions: +------------------------ + +- MPLS is not supported on `FreeBSD`. MPLS requires a Linux Kernel + (4.5 or higher). LDP can be built, but may have limited use + without MPLS + +Install required packages +------------------------- + +Add packages: +(Allow the install of the package managment tool if this is first package install and asked) + + pkg install git autoconf automake libtool gmake gawk json-c pkgconf \ + bison flex py27-pytest + +Make sure there is no /usr/bin/flex preinstalled (and use the newly installed in /usr/local/bin): +(FreeBSD frequently provides a older flex as part of the base OS whcih takes preference in path) + + rm -f /usr/bin/flex + +Get FRR, compile it and install it (from Git) +--------------------------------------------- + +**This assumes you want to build and install FRR from source and not using any packages** + +### Add frr group and user + + pw groupadd frr -g 101 + pw groupadd frrvty -g 102 + pw adduser frr -g 101 -u 101 -G 102 -c "FRR suite" \ + -d /usr/local/etc/frr -s /usr/sbin/nologin + +(You may prefer different options on configure statement. These are just an example) + + git clone https://github.com/freerangerouting/frr.git frr + cd frr + git checkout stable/2.0 + ./bootstrap.sh + export MAKE=gmake + export LDFLAGS="-L/usr/local/lib" + export CPPFLAGS="-I/usr/local/include" + ./configure \ + --sysconfdir=/usr/local/etc/frr \ + --enable-pkgsrcrcdir=/usr/pkg/share/examples/rc.d \ + --localstatedir=/var/run/frr \ + --prefix=/usr/local \ + --enable-ospfclient=yes \ + --enable-ospfapi=yes \ + --enable-multipath=64 \ + --enable-user=frr \ + --enable-group=frr \ + --enable-vty-group=frrvty \ + --enable-configfile-mask=0640 \ + --enable-logfile-mask=0640 \ + --enable-rtadv \ + --enable-tcp-zebra \ + --enable-fpm \ + --with-pkg-git-version \ + --with-pkg-extra-version=-MyOwnFRRVersion + gmake + gmake check + sudo gmake install + +### Create empty FRR configuration files + sudo mkdir /usr/local/etc/frr + sudo touch /usr/local/etc/frr/zebra.conf + sudo touch /usr/local/etc/frr/bgpd.conf + sudo touch /usr/local/etc/frr/ospfd.conf + sudo touch /usr/local/etc/frr/ospf6d.conf + sudo touch /usr/local/etc/frr/isisd.conf + sudo touch /usr/local/etc/frr/ripd.conf + sudo touch /usr/local/etc/frr/ripngd.conf + sudo touch /usr/local/etc/frr/pimd.conf + sudo chown -R frr:frr /usr/local/etc/frr + sudo touch /usr/local/etc/frr/vtysh.conf + sudo chown frr:frrvty /usr/local/etc/frr/vtysh.conf + sudo chmod 640 /usr/local/etc/frr/*.conf + +### Enable IP & IPv6 forwarding + +Add the following lines to the end of `/etc/sysctl.conf`: + + # Routing: We need to forward packets + net.inet.ip.forwarding=1 + net.inet6.ip6.forwarding=1 + +**Reboot** or use `sysctl` to apply the same config to the running system diff --git a/doc/Building_FRR_on_FreeBSD11.md b/doc/Building_FRR_on_FreeBSD11.md new file mode 100644 index 0000000000..fec06bc092 --- /dev/null +++ b/doc/Building_FRR_on_FreeBSD11.md @@ -0,0 +1,91 @@ +Building FRR on FreeBSD 11 from Git Source +========================================== + +FreeBSD 11 restrictions: +------------------------ + +- MPLS is not supported on `FreeBSD`. MPLS requires a Linux Kernel + (4.5 or higher). LDP can be built, but may have limited use + without MPLS + +Install required packages +------------------------- + +Add packages: +(Allow the install of the package managment tool if this is first package install and asked) + + pkg install git autoconf automake libtool gmake gawk json-c pkgconf \ + bison flex py27-pytest + +Make sure there is no /usr/bin/flex preinstalled (and use the newly installed in /usr/local/bin): +(FreeBSD frequently provides a older flex as part of the base OS whcih takes preference in path) + + rm -f /usr/bin/flex + +Get FRR, compile it and install it (from Git) +--------------------------------------------- + +**This assumes you want to build and install FRR from source and not using any packages** + +### Add frr group and user + + pw groupadd frr -g 101 + pw groupadd frrvty -g 102 + pw adduser frr -g 101 -u 101 -G 102 -c "FRR suite" \ + -d /usr/local/etc/frr -s /usr/sbin/nologin + +(You may prefer different options on configure statement. These are just an example) + + git clone https://github.com/freerangerouting/frr.git frr + cd frr + git checkout stable/2.0 + ./bootstrap.sh + export MAKE=gmake + export LDFLAGS="-L/usr/local/lib" + export CPPFLAGS="-I/usr/local/include" + ./configure \ + --sysconfdir=/usr/local/etc/frr \ + --enable-pkgsrcrcdir=/usr/pkg/share/examples/rc.d \ + --localstatedir=/var/run/frr \ + --prefix=/usr/local \ + --enable-ospfclient=yes \ + --enable-ospfapi=yes \ + --enable-multipath=64 \ + --enable-user=frr \ + --enable-group=frr \ + --enable-vty-group=frrvty \ + --enable-configfile-mask=0640 \ + --enable-logfile-mask=0640 \ + --enable-rtadv \ + --enable-tcp-zebra \ + --enable-fpm \ + --with-pkg-git-version \ + --with-pkg-extra-version=-MyOwnFRRVersion + gmake + gmake check + sudo gmake install + +### Create empty FRR configuration files + sudo mkdir /usr/local/etc/frr + sudo touch /usr/local/etc/frr/zebra.conf + sudo touch /usr/local/etc/frr/bgpd.conf + sudo touch /usr/local/etc/frr/ospfd.conf + sudo touch /usr/local/etc/frr/ospf6d.conf + sudo touch /usr/local/etc/frr/isisd.conf + sudo touch /usr/local/etc/frr/ripd.conf + sudo touch /usr/local/etc/frr/ripngd.conf + sudo touch /usr/local/etc/frr/pimd.conf + sudo chown -R frr:frr /usr/local/etc/frr + sudo touch /usr/local/etc/frr/vtysh.conf + sudo chown frr:frrvty /usr/local/etc/frr/vtysh.conf + sudo chmod 640 /usr/local/etc/frr/*.conf + +### Enable IP & IPv6 forwarding + +Add the following lines to the end of `/etc/sysctl.conf`: + + # Routing: We need to forward packets + net.inet.ip.forwarding=1 + net.inet6.ip6.forwarding=1 + +**Reboot** or use `sysctl` to apply the same config to the running system diff --git a/doc/Building_FRR_on_FreeBSD9.md b/doc/Building_FRR_on_FreeBSD9.md new file mode 100644 index 0000000000..37fdd92b15 --- /dev/null +++ b/doc/Building_FRR_on_FreeBSD9.md @@ -0,0 +1,91 @@ +Building FRR on FreeBSD 9 from Git Source +========================================= + +FreeBSD 9 restrictions: +----------------------- + +- MPLS is not supported on `FreeBSD`. MPLS requires a Linux Kernel + (4.5 or higher). LDP can be built, but may have limited use + without MPLS + +Install required packages +------------------------- + +Add packages: +(Allow the install of the package managment tool if this is first package install and asked) + + pkg install -y git autoconf automake libtool gmake gawk \ + pkgconf texinfo json-c bison flex py27-pytest + +Make sure there is no /usr/bin/flex preinstalled (and use the newly installed in /usr/local/bin): +(FreeBSD frequently provides a older flex as part of the base OS whcih takes preference in path) + + rm -f /usr/bin/flex + +Get FRR, compile it and install it (from Git) +--------------------------------------------- + +**This assumes you want to build and install FRR from source and not using any packages** + +### Add frr group and user + + pw groupadd frr -g 101 + pw groupadd frrvty -g 102 + pw adduser frr -g 101 -u 101 -G 102 -c "FRR suite" \ + -d /usr/local/etc/frr -s /usr/sbin/nologin + +(You may prefer different options on configure statement. These are just an example) + + git clone https://github.com/freerangerouting/frr.git frr + cd frr + git checkout stable/2.0 + ./bootstrap.sh + export MAKE=gmake + export LDFLAGS="-L/usr/local/lib" + export CPPFLAGS="-I/usr/local/include" + ./configure \ + --sysconfdir=/usr/local/etc/frr \ + --enable-pkgsrcrcdir=/usr/pkg/share/examples/rc.d \ + --localstatedir=/var/run/frr \ + --prefix=/usr/local \ + --enable-ospfclient=yes \ + --enable-ospfapi=yes \ + --enable-multipath=64 \ + --enable-user=frr \ + --enable-group=frr \ + --enable-vty-group=frrvty \ + --enable-configfile-mask=0640 \ + --enable-logfile-mask=0640 \ + --enable-rtadv \ + --enable-tcp-zebra \ + --enable-fpm \ + --with-pkg-git-version \ + --with-pkg-extra-version=-MyOwnFRRVersion + gmake + gmake check + sudo gmake install + +### Create empty FRR configuration files + sudo mkdir /usr/local/etc/frr + sudo touch /usr/local/etc/frr/zebra.conf + sudo touch /usr/local/etc/frr/bgpd.conf + sudo touch /usr/local/etc/frr/ospfd.conf + sudo touch /usr/local/etc/frr/ospf6d.conf + sudo touch /usr/local/etc/frr/isisd.conf + sudo touch /usr/local/etc/frr/ripd.conf + sudo touch /usr/local/etc/frr/ripngd.conf + sudo touch /usr/local/etc/frr/pimd.conf + sudo chown -R frr:frr /usr/local/etc/frr + sudo touch /usr/local/etc/frr/vtysh.conf + sudo chown frr:frrvty /usr/local/etc/frr/vtysh.conf + sudo chmod 640 /usr/local/etc/frr/*.conf + +### Enable IP & IPv6 forwarding + +Add the following lines to the end of `/etc/sysctl.conf`: + + # Routing: We need to forward packets + net.inet.ip.forwarding=1 + net.inet6.ip6.forwarding=1 + +**Reboot** or use `sysctl` to apply the same config to the running system diff --git a/doc/Building_FRR_on_NetBSD6.md b/doc/Building_FRR_on_NetBSD6.md new file mode 100644 index 0000000000..0d3f108056 --- /dev/null +++ b/doc/Building_FRR_on_NetBSD6.md @@ -0,0 +1,116 @@ +Building FRR on NetBSD 6 from Git Source +======================================== + +NetBSD 6 restrictions: +---------------------- + +- MPLS is not supported on `NetBSD`. MPLS requires a Linux Kernel + (4.5 or higher). LDP can be built, but may have limited use + without MPLS + +Install required packages +------------------------- +Configure Package location: + + PKG_PATH="ftp://ftp.NetBSD.org/pub/pkgsrc/packages/NetBSD/`uname -m`/`uname -r`/All" + export PKG_PATH + +Add packages: + + sudo pkg_add git autoconf automake libtool gmake gawk openssl pkg-config \ + json-c p5-XML-LibXML python27 py27-test + +Install SSL Root Certificates (for git https access): + + sudo pkg_add mozilla-rootcerts + sudo touch /etc/openssl/openssl.cnf + sudo mozilla-rootcerts install + +Select default Python and py.test + + sudo ln -s /usr/pkg/bin/python2.7 /usr/bin/python + sudo ln -s /usr/pkg/bin/py.test-2.7 /usr/bin/py.test + +Get FRR, compile it and install it (from Git) +------------------------------------------------ + +### Add frr groups and user + + sudo groupadd -g 92 frr + sudo groupadd -g 93 frrvty + sudo useradd -g 92 -u 92 -G frrvty -c "FRR suite" \ + -d /nonexistent -s /sbin/nologin frr + +### Download Source, configure and compile it +(You may prefer different options on configure statement. These are just an example) + + git clone https://github.com/freerangerouting/frr.git frr + cd frr + git checkout stable/2.0 + ./bootstrap.sh + MAKE=gmake + export LDFLAGS="-L/usr/pkg/lib -R/usr/pkg/lib" + export CPPFLAGS="-I/usr/pkg/include" + ./configure \ + --sysconfdir=/usr/pkg/etc/frr \ + --enable-exampledir=/usr/pkg/share/examples/frr \ + --enable-pkgsrcrcdir=/usr/pkg/share/examples/rc.d \ + --localstatedir=/var/run/frr \ + --enable-ospfclient=yes \ + --enable-ospfapi=yes \ + --enable-multipath=64 \ + --enable-user=frr \ + --enable-group=frr \ + --enable-vty-group=frrvty \ + --enable-configfile-mask=0640 \ + --enable-logfile-mask=0640 \ + --enable-rtadv \ + --enable-tcp-zebra \ + --enable-fpm \ + --with-pkg-git-version \ + --with-pkg-extra-version=-MyOwnFRRVersion + gmake + gmake check + sudo gmake install + +### Create empty FRR configuration files + sudo mkdir /var/log/frr + sudo mkdir /usr/pkg/etc/frr + sudo touch /usr/pkg/etc/frr/zebra.conf + sudo touch /usr/pkg/etc/frr/bgpd.conf + sudo touch /usr/pkg/etc/frr/ospfd.conf + sudo touch /usr/pkg/etc/frr/ospf6d.conf + sudo touch /usr/pkg/etc/frr/isisd.conf + sudo touch /usr/pkg/etc/frr/ripd.conf + sudo touch /usr/pkg/etc/frr/ripngd.conf + sudo touch /usr/pkg/etc/frr/pimd.conf + sudo chown -R frr:frr /usr/pkg/etc/frr + sudo touch /usr/local/etc/frr/vtysh.conf + sudo chown frr:frrvty /usr/pkg/etc/frr/*.conf + sudo chmod 640 /usr/pkg/etc/frr/*.conf + +### Enable IP & IPv6 forwarding + +Add the following lines to the end of `/etc/sysctl.conf`: + + # Routing: We need to forward packets + net.inet.ip.forwarding=1 + net.inet6.ip6.forwarding=1 + +**Reboot** or use `sysctl` to apply the same config to the running system + +### Install rc.d init files + cp pkgsrc/*.sh /etc/rc.d/ + chmod 555 /etc/rc.d/*.sh + +### Enable FRR processes +(Enable the required processes only) + + echo "zebra=YES" >> /etc/rc.conf + echo "bgpd=YES" >> /etc/rc.conf + echo "ospfd=YES" >> /etc/rc.conf + echo "ospf6d=YES" >> /etc/rc.conf + echo "isisd=YES" >> /etc/rc.conf + echo "ripngd=YES" >> /etc/rc.conf + echo "ripd=YES" >> /etc/rc.conf + echo "pimd=YES" >> /etc/rc.conf diff --git a/doc/Building_FRR_on_NetBSD7.md b/doc/Building_FRR_on_NetBSD7.md new file mode 100644 index 0000000000..22c468a6a1 --- /dev/null +++ b/doc/Building_FRR_on_NetBSD7.md @@ -0,0 +1,109 @@ +Building FRR on NetBSD 7 from Git Source +======================================== + +NetBSD 7 restrictions: +---------------------- + +- MPLS is not supported on `NetBSD`. MPLS requires a Linux Kernel + (4.5 or higher). LDP can be built, but may have limited use + without MPLS + +Install required packages +------------------------- + + sudo pkgin install git autoconf automake libtool gmake gawk openssl pkg-config \ + json-c p5-XML-LibXML python27 py27-test + +Install SSL Root Certificates (for git https access): + + sudo pkgin install mozilla-rootcerts + sudo touch /etc/openssl/openssl.cnf + sudo mozilla-rootcerts install + +Select default Python and py.test + + sudo ln -s /usr/pkg/bin/python2.7 /usr/bin/python + sudo ln -s /usr/pkg/bin/py.test-2.7 /usr/bin/py.test + +Get FRR, compile it and install it (from Git) +------------------------------------------------ + +### Add frr groups and user + + sudo groupadd -g 92 frr + sudo groupadd -g 93 frrvty + sudo useradd -g 92 -u 92 -G frrvty -c "FRR suite" \ + -d /nonexistent -s /sbin/nologin frr + +### Download Source, configure and compile it +(You may prefer different options on configure statement. These are just an example) + + git clone https://github.com/freerangerouting/frr.git frr + cd frr + git checkout stable/2.0 + ./bootstrap.sh + MAKE=gmake + export LDFLAGS="-L/usr/pkg/lib -R/usr/pkg/lib" + export CPPFLAGS="-I/usr/pkg/include" + ./configure \ + --sysconfdir=/usr/pkg/etc/frr \ + --enable-exampledir=/usr/pkg/share/examples/frr \ + --enable-pkgsrcrcdir=/usr/pkg/share/examples/rc.d \ + --localstatedir=/var/run/frr \ + --enable-ospfclient=yes \ + --enable-ospfapi=yes \ + --enable-multipath=64 \ + --enable-user=frr \ + --enable-group=frr \ + --enable-vty-group=frrvty \ + --enable-configfile-mask=0640 \ + --enable-logfile-mask=0640 \ + --enable-rtadv \ + --enable-tcp-zebra \ + --enable-fpm \ + --with-pkg-git-version \ + --with-pkg-extra-version=-MyOwnFRRVersion + gmake + gmake check + sudo gmake install + +### Create empty FRR configuration files + sudo mkdir /usr/pkg/etc/frr + sudo touch /usr/pkg/etc/frr/zebra.conf + sudo touch /usr/pkg/etc/frr/bgpd.conf + sudo touch /usr/pkg/etc/frr/ospfd.conf + sudo touch /usr/pkg/etc/frr/ospf6d.conf + sudo touch /usr/pkg/etc/frr/isisd.conf + sudo touch /usr/pkg/etc/frr/ripd.conf + sudo touch /usr/pkg/etc/frr/ripngd.conf + sudo touch /usr/pkg/etc/frr/pimd.conf + sudo chown -R frr:frr /usr/pkg/etc/frr + sudo touch /usr/local/etc/frr/vtysh.conf + sudo chown frr:frrvty /usr/pkg/etc/frr/*.conf + sudo chmod 640 /usr/pkg/etc/frr/*.conf + +### Enable IP & IPv6 forwarding + +Add the following lines to the end of `/etc/sysctl.conf`: + + # Routing: We need to forward packets + net.inet.ip.forwarding=1 + net.inet6.ip6.forwarding=1 + +**Reboot** or use `sysctl` to apply the same config to the running system + +### Install rc.d init files + cp pkgsrc/*.sh /etc/rc.d/ + chmod 555 /etc/rc.d/*.sh + +### Enable FRR processes +(Enable the required processes only) + + echo "zebra=YES" >> /etc/rc.conf + echo "bgpd=YES" >> /etc/rc.conf + echo "ospfd=YES" >> /etc/rc.conf + echo "ospf6d=YES" >> /etc/rc.conf + echo "isisd=YES" >> /etc/rc.conf + echo "ripngd=YES" >> /etc/rc.conf + echo "ripd=YES" >> /etc/rc.conf + echo "pimd=YES" >> /etc/rc.conf diff --git a/doc/Building_FRR_on_OmniOS.md b/doc/Building_FRR_on_OmniOS.md new file mode 100644 index 0000000000..12acc92886 --- /dev/null +++ b/doc/Building_FRR_on_OmniOS.md @@ -0,0 +1,120 @@ +Building FRR on OmniOS (OpenSolaris) from Git Source +==================================================== + +OmniOS restrictions: +-------------------- + +- MPLS is not supported on `OmniOS` or `Solaris`. MPLS requires a Linux Kernel + (4.5 or higher). LDP can be built, but may have limited use without MPLS + +### Enable IP & IPv6 forwarding + + routeadm -e ipv4-forwarding + routeadm -e ipv6-forwarding + +Install required packages +------------------------- + +Add packages: + + pkg install \ + developer/build/autoconf \ + developer/build/automake \ + developer/lexer/flex \ + developer/parser/bison \ + developer/object-file \ + developer/linker \ + developer/library/lint \ + developer/build/gnu-make \ + developer/gcc51 \ + library/idnkit \ + library/idnkit/header-idnkit \ + system/header \ + system/library/math/header-math \ + git libtool gawk pkg-config + +Add additional Solaris packages: + + pkgadd -d http://get.opencsw.org/now + /opt/csw/bin/pkgutil -U + /opt/csw/bin/pkgutil -y -i texinfo + /opt/csw/bin/pkgutil -y -i perl + /opt/csw/bin/pkgutil -y -i libjson_c_dev + /opt/csw/bin/pkgutil -y -i python27 py_pip + +Add libjson to Solaris equivalent of ld.so.conf + + crle -l /opt/csw/lib -u + +Add Perl packages: + + cpan + cpan[1]> install XML::LibXML + cpan[2]> exit + +Add pytest: + + pip install pytest + +Select Python 2.7 as default (required for pytest) + + rm -f /usr/bin/python + ln -s /opt/csw/bin/python2.7 /usr/bin/python + +Fix PATH for all users and non-interactive sessions. Edit `/etc/default/login` and add the following default PATH: + + PATH=/usr/gnu/bin:/usr/bin:/usr/sbin:/sbin:/opt/csw/bin + +Edit `~/.profile` and add the following default PATH: + + PATH=/usr/gnu/bin:/usr/bin:/usr/sbin:/sbin:/opt/csw/bin + +Get FRR, compile it and install it (from Git) +--------------------------------------------- + +**This assumes you want to build and install FRR from source and not using any packages** + +### Add frr group and user + + sudo groupadd -g 93 frr + sudo groupadd -g 94 frrvty + sudo useradd -g 93 -u 93 -G frrvty -c "FRR suite" \ + -d /nonexistent -s /bin/false frr + +(You may prefer different options on configure statement. These are just an example) + + git clone https://github.com/freerangerouting/frr.git frr + cd frr + git checkout stable/2.0 + ./bootstrap.sh + export MAKE=gmake + export LDFLAGS="-L/opt/csw/lib" + export CPPFLAGS="-I/opt/csw/include" + ./configure \ + --sysconfdir=/etc/frr \ + --enable-exampledir=/usr/share/doc/frr/examples/ \ + --localstatedir=/var/run/frr \ + --sbindir=/usr/lib/frr \ + --enable-vtysh \ + --enable-watchfrr \ + --enable-ospfclient=yes \ + --enable-ospfapi=yes \ + --enable-multipath=64 \ + --enable-user=frr \ + --enable-group=frr \ + --enable-vty-group=frrvty \ + --enable-configfile-mask=0640 \ + --enable-logfile-mask=0640 \ + --enable-rtadv \ + --enable-tcp-zebra \ + --enable-fpm \ + --with-pkg-git-version \ + --with-pkg-extra-version=-MyOwnFRRVersion + gmake + gmake check + sudo gmake install + +### Enable IP & IPv6 forwarding + + routeadm -e ipv4-forwarding + routeadm -e ipv6-forwarding diff --git a/doc/Building_FRR_on_OpenBSD6.md b/doc/Building_FRR_on_OpenBSD6.md new file mode 100644 index 0000000000..3f390d5eb7 --- /dev/null +++ b/doc/Building_FRR_on_OpenBSD6.md @@ -0,0 +1,126 @@ +Building FRR on OpenBSD 6 from Git Source +========================================= + +OpenBSD restrictions: +--------------------- + +- MPLS is not tested on `OpenBSD`. It may work as it shares the + sources with the LDPd on OpenBSD. Bug reports and fixes are welcome + +Install required packages +------------------------- + +Configure PKG_PATH + + export PKG_PATH=http://ftp5.usa.openbsd.org/pub/OpenBSD/$(uname -r)/packages/$(machine -a)/ + +Add packages: + + pkg_add git autoconf-2.69p2 automake-1.15p0 libtool + pkg_add gmake gawk dejagnu openssl json-c p5-XML-LibXML py-test + +Select Python2.7 as default (required for pytest) + + ln -s /usr/local/bin/python2.7 /usr/local/bin/python + +Get FRR, compile it and install it (from Git) +--------------------------------------------- + +**This assumes you want to build and install FRR from source and not using any packages** + +### Add frr group and user + + groupadd -g 525 _frr + groupadd -g 526 _frrvty + useradd -g 525 -u 525 -c "FRR suite" -G _frrvty \ + -d /nonexistent -s /sbin/nologin _frr + +### Download Source, configure and compile it +(You may prefer different options on configure statement. These are just an example) + + git clone https://github.com/freerangerouting/frr.git frr + cd frr + git checkout stable/2.0 + ./bootstrap.sh + export LDFLAGS="-L/usr/local/lib" + export CPPFLAGS="-I/usr/local/include" + ./configure \ + --sysconfdir=/etc/frr \ + --localstatedir=/var/frr \ + --enable-pimd \ + --enable-ospfclient=yes \ + --enable-ospfapi=yes \ + --enable-multipath=64 \ + --enable-user=_frr \ + --enable-group=_frr \ + --enable-vty-group=_frrvty \ + --enable-configfile-mask=0640 \ + --enable-logfile-mask=0640 \ + --enable-rtadv \ + --enable-tcp-zebra \ + --enable-fpm \ + --enable-ldpd \ + --with-pkg-git-version \ + --with-pkg-extra-version=-MyOwnFRRVersion + gmake + gmake check + sudo gmake install + +### Create empty FRR configuration files + + sudo mkdir /var/frr + sudo chown _frr:_frr /var/frr + sudo chmod 755 /var/frr + sudo mkdir /etc/frr + sudo touch /etc/frr/zebra.conf + sudo touch /etc/frr/bgpd.conf + sudo touch /etc/frr/ospfd.conf + sudo touch /etc/frr/ospf6d.conf + sudo touch /etc/frr/isisd.conf + sudo touch /etc/frr/ripd.conf + sudo touch /etc/frr/ripngd.conf + sudo touch /etc/frr/pimd.conf + sudo touch /etc/frr/ldpd.conf + sudo chown -R _frr:_frr /etc/frr + sudo touch /etc/frr/vtysh.conf + sudo chown -R _frr:_frrvty /etc/frr/vtysh.conf + sudo chmod 750 /etc/frr + sudo chmod 640 /etc/frr/*.conf + +### Enable IP & IPv6 forwarding + +Add the following lines to the end of `/etc/rc.conf`: + + net.inet6.ip6.forwarding=1 # 1=Permit forwarding of IPv6 packets + net.inet6.ip6.mforwarding=1 # 1=Permit forwarding of IPv6 multicast packets + net.inet6.ip6.multipath=1 # 1=Enable IPv6 multipath routing + +**Reboot** to apply the config to the system + +### Install rc.d init files +(create them in /etc/rc.d - no example are included at this time with FRR source) + +Example (for zebra - store as `/etc/rc.d/frr_zebra.sh`) + + #!/bin/sh + # + # $OpenBSD: frr_zebra.rc,v 1.1 2013/04/18 20:29:08 sthen Exp $ + + daemon="/usr/local/sbin/zebra -d" + + . /etc/rc.d/rc.subr + + rc_cmd $1 + +### Enable FRR processes +(Enable the required processes only) + + echo "frr_zebra=YES" >> /etc/rc.conf + echo "frr_bgpd=YES" >> /etc/rc.conf + echo "frr_ospfd=YES" >> /etc/rc.conf + echo "frr_ospf6d=YES" >> /etc/rc.conf + echo "frr_isisd=YES" >> /etc/rc.conf + echo "frr_ripngd=YES" >> /etc/rc.conf + echo "frr_ripd=YES" >> /etc/rc.conf + echo "frr_pimd=YES" >> /etc/rc.conf + echo "frr_ldpd=YES" >> /etc/rc.conf diff --git a/doc/Building_FRR_on_Ubuntu1204.md b/doc/Building_FRR_on_Ubuntu1204.md new file mode 100644 index 0000000000..98ee2b831a --- /dev/null +++ b/doc/Building_FRR_on_Ubuntu1204.md @@ -0,0 +1,128 @@ +Building FRR on Ubuntu 12.04LTS from Git Source +=============================================== + +- MPLS is not supported on `Ubuntu 12.04` with default kernel. MPLS requires + Linux Kernel 4.5 or higher (LDP can be built, but may have limited use + without MPLS) + For an updated Ubuntu Kernel, see http://kernel.ubuntu.com/~kernel-ppa/mainline/ + +Install required packages +------------------------- + +Add packages: + + apt-get install git autoconf automake libtool make gawk libreadline-dev texinfo \ + libpam0g-dev dejagnu libjson0 pkg-config libpam0g-dev libjson0-dev flex \ + python-pytest + +Install newer bison from 14.04 package source (Ubuntu 12.04 package source is too old) + + mkdir builddir + cd builddir + wget http://archive.ubuntu.com/ubuntu/pool/main/b/bison/bison_3.0.2.dfsg-2.dsc + wget http://archive.ubuntu.com/ubuntu/pool/main/b/bison/bison_3.0.2.dfsg.orig.tar.bz2 + wget http://archive.ubuntu.com/ubuntu/pool/main/b/bison/bison_3.0.2.dfsg-2.debian.tar.gz + tar -jxvf bison_3.0.2.dfsg.orig.tar.bz2 + cd bison-3.0.2.dfsg/ + tar xzf ../bison_3.0.2.dfsg-2.debian.tar.gz + sudo apt-get build-dep bison + debuild -b -uc -us + cd .. + sudo dpkg -i ./libbison-dev_3.0.2.dfsg-2_amd64.deb ./bison_3.0.2.dfsg-2_amd64.deb + cd .. + rm -rf builddir + +Install newer version of autoconf and automake: + + wget http://ftp.gnu.org/gnu/autoconf/autoconf-2.69.tar.gz + tar xvf autoconf-2.69.tar.gz + cd autoconf-2.69 + ./configure --prefix=/usr + make + sudo make install + cd .. + + wget http://ftp.gnu.org/gnu/automake/automake-1.15.tar.gz + tar xvf automake-1.15.tar.gz + cd automake-1.15 + ./configure --prefix=/usr + make + sudo make install + cd .. + +Get FRR, compile it and install it (from Git) +--------------------------------------------- + +**This assumes you want to build and install FRR from source and not using any packages** + +### Add frr groups and user + + sudo groupadd -g 92 frr + sudo groupadd -r -g 85 frrvty + sudo adduser --system --ingroup frr --groups frrvty --home /var/run/frr/ \ + --gecos "FRR suite" --shell /sbin/nologin frr + +### Download Source, configure and compile it +(You may prefer different options on configure statement. These are just an example.) + + git clone https://github.com/freerangerouting/frr.git frr + cd frr + git checkout stable/2.0 + ./bootstrap.sh + ./configure \ + --enable-exampledir=/usr/share/doc/frr/examples/ \ + --localstatedir=/var/run/frr \ + --sbindir=/usr/lib/frr \ + --sysconfdir=/etc/frr \ + --enable-pimd \ + --enable-watchfrr \ + --enable-ospfclient=yes \ + --enable-ospfapi=yes \ + --enable-multipath=64 \ + --enable-user=frr \ + --enable-group=frr \ + --enable-vty-group=frrvty \ + --enable-configfile-mask=0640 \ + --enable-logfile-mask=0640 \ + --enable-rtadv \ + --enable-tcp-zebra \ + --enable-fpm \ + --enable-ldpd \ + --with-pkg-git-version \ + --with-pkg-extra-version=-MyOwnFRRVersion + make + make check + sudo make install + +### Create empty FRR configuration files + + sudo mkdir /var/log/frr + sudo chown frr:fee /var/log/frr + sudo mkdir /etc/frr + sudo touch /etc/frr/etc/zebra.conf + sudo touch /etc/frr/etc/bgpd.conf + sudo touch /etc/frr/etc/ospfd.conf + sudo touch /etc/frr/etc/ospf6d.conf + sudo touch /etc/frr/etc/isisd.conf + sudo touch /etc/frr/etc/ripd.conf + sudo touch /etc/frr/etc/ripngd.conf + sudo touch /etc/frr/etc/pimd.conf + sudo touch /etc/frr/etc/ldpd.conf + sudo chown frr:frr /etc/frr/ + sudo touch /etc/frr/etc/vtysh.conf + sudo chown frr:frrvty /etc/frr/etc/vtysh.conf + sudo chmod 640 /etc/frr/*.conf + +### Enable IP & IPv6 forwarding + +Edit `/etc/sysctl.conf` and uncomment the following values (ignore the other settings) + + # Uncomment the next line to enable packet forwarding for IPv4 + net.ipv4.ip_forward=1 + + # Uncomment the next line to enable packet forwarding for IPv6 + # Enabling this option disables Stateless Address Autoconfiguration + # based on Router Advertisements for this host + net.ipv6.conf.all.forwarding=1 + +**Reboot** or use `sysctl` to apply the same config to the running system diff --git a/doc/Building_FRR_on_Ubuntu1404.md b/doc/Building_FRR_on_Ubuntu1404.md new file mode 100644 index 0000000000..3198428596 --- /dev/null +++ b/doc/Building_FRR_on_Ubuntu1404.md @@ -0,0 +1,88 @@ +Building FRR on Ubuntu 14.04LTS from Git Source +=============================================== + +- MPLS is not supported on `Ubuntu 14.04` with default kernel. MPLS requires + Linux Kernel 4.5 or higher (LDP can be built, but may have limited use + without MPLS) + For an updated Ubuntu Kernel, see http://kernel.ubuntu.com/~kernel-ppa/mainline/ + +Install required packages +------------------------- + +Add packages: + + apt-get install git autoconf automake libtool make gawk libreadline-dev texinfo \ + dejagnu pkg-config libpam0g-dev libjson-c-dev bison flex python-pytest + +Get FRR, compile it and install it (from Git) +--------------------------------------------- + +### Add frr groups and user + + sudo groupadd -g 92 frr + sudo groupadd -r -g 85 frrvty + sudo adduser --system --ingroup frr --groups frrvty --home /var/run/frr/ \ + --gecos "FRR suite" --shell /sbin/nologin frr + +### Download Source, configure and compile it +(You may prefer different options on configure statement. These are just an example.) + + git clone https://github.com/freerangerouting/frr.git frr + cd frr + git checkout stable/2.0 + ./bootstrap.sh + ./configure \ + --enable-exampledir=/usr/share/doc/frr/examples/ \ + --localstatedir=/var/run/frr \ + --sbindir=/usr/lib/frr \ + --sysconfdir=/etc/frr \ + --enable-pimd \ + --enable-watchfrr \ + --enable-ospfclient=yes \ + --enable-ospfapi=yes \ + --enable-multipath=64 \ + --enable-user=frr \ + --enable-group=frr \ + --enable-vty-group=frrvty \ + --enable-configfile-mask=0640 \ + --enable-logfile-mask=0640 \ + --enable-rtadv \ + --enable-tcp-zebra \ + --enable-fpm \ + --with-pkg-git-version \ + --with-pkg-extra-version=-MyOwnFRRVersion + make + make check + sudo make install + +### Create empty FRR configuration files + + sudo mkdir /var/log/frr + sudo chown frr:fee /var/log/frr + sudo mkdir /etc/frr + sudo touch /etc/frr/etc/zebra.conf + sudo touch /etc/frr/etc/bgpd.conf + sudo touch /etc/frr/etc/ospfd.conf + sudo touch /etc/frr/etc/ospf6d.conf + sudo touch /etc/frr/etc/isisd.conf + sudo touch /etc/frr/etc/ripd.conf + sudo touch /etc/frr/etc/ripngd.conf + sudo touch /etc/frr/etc/pimd.conf + sudo chown frr:frr /etc/frr/ + sudo touch /etc/frr/etc/vtysh.conf + sudo chown frr:frrvty /etc/frr/etc/vtysh.conf + sudo chmod 640 /etc/frr/*.conf + +### Enable IP & IPv6 forwarding + +Edit `/etc/sysctl.conf` and uncomment the following values (ignore the other settings) + + # Uncomment the next line to enable packet forwarding for IPv4 + net.ipv4.ip_forward=1 + + # Uncomment the next line to enable packet forwarding for IPv6 + # Enabling this option disables Stateless Address Autoconfiguration + # based on Router Advertisements for this host + net.ipv6.conf.all.forwarding=1 + +**Reboot** or use `sysctl` to apply the same config to the running system diff --git a/doc/Building_FRR_on_Ubuntu1604.md b/doc/Building_FRR_on_Ubuntu1604.md new file mode 100644 index 0000000000..03f4d6d9e4 --- /dev/null +++ b/doc/Building_FRR_on_Ubuntu1604.md @@ -0,0 +1,111 @@ +Building FRR on Ubuntu 12.04LTS from Git Source +=============================================== + +- MPLS is not supported on `Ubuntu 12.04` with default kernel. MPLS requires + Linux Kernel 4.5 or higher (LDP can be built, but may have limited use + without MPLS) + For an updated Ubuntu Kernel, see http://kernel.ubuntu.com/~kernel-ppa/mainline/ + +Install required packages +------------------------- + +Add packages: + + apt-get install git autoconf automake libtool make gawk libreadline-dev texinfo \ + dejagnu pkg-config libpam0g-dev libjson-c-dev bison flex python-pytest + +Get FRR, compile it and install it (from Git) +--------------------------------------------- + +**This assumes you want to build and install FRR from source and not using any packages** + +### Add frr groups and user + + sudo groupadd -g 92 frr + sudo groupadd -r -g 85 frrvty + sudo adduser --system --ingroup frr --groups frrvty --home /var/run/frr/ \ + --gecos "FRR suite" --shell /sbin/nologin frr + +### Download Source, configure and compile it +(You may prefer different options on configure statement. These are just an example.) + + git clone https://github.com/freerangerouting/frr.git frr + cd frr + git checkout stable/2.0 + ./bootstrap.sh + ./configure \ + --enable-exampledir=/usr/share/doc/frr/examples/ \ + --localstatedir=/var/run/frr \ + --sbindir=/usr/lib/frr \ + --sysconfdir=/etc/frr \ + --enable-pimd \ + --enable-watchfrr \ + --enable-ospfclient=yes \ + --enable-ospfapi=yes \ + --enable-multipath=64 \ + --enable-user=frr \ + --enable-group=frr \ + --enable-vty-group=frrvty \ + --enable-configfile-mask=0640 \ + --enable-logfile-mask=0640 \ + --enable-rtadv \ + --enable-tcp-zebra \ + --enable-fpm \ + --enable-ldpd \ + --with-pkg-git-version \ + --with-pkg-extra-version=-MyOwnFRRVersion + make + make check + sudo make install + +### Create empty FRR configuration files + + sudo mkdir /var/log/frr + sudo chown frr:fee /var/log/frr + sudo mkdir /etc/frr + sudo touch /etc/frr/etc/zebra.conf + sudo touch /etc/frr/etc/bgpd.conf + sudo touch /etc/frr/etc/ospfd.conf + sudo touch /etc/frr/etc/ospf6d.conf + sudo touch /etc/frr/etc/isisd.conf + sudo touch /etc/frr/etc/ripd.conf + sudo touch /etc/frr/etc/ripngd.conf + sudo touch /etc/frr/etc/pimd.conf + sudo touch /etc/frr/etc/ldpd.conf + sudo chown frr:frr /etc/frr/ + sudo touch /etc/frr/etc/vtysh.conf + sudo chown frr:frrvty /etc/frr/etc/vtysh.conf + sudo chmod 640 /etc/frr/*.conf + +### Enable IP & IPv6 forwarding + +Edit `/etc/sysctl.conf` and uncomment the following values (ignore the other settings) + + # Uncomment the next line to enable packet forwarding for IPv4 + net.ipv4.ip_forward=1 + + # Uncomment the next line to enable packet forwarding for IPv6 + # Enabling this option disables Stateless Address Autoconfiguration + # based on Router Advertisements for this host + net.ipv6.conf.all.forwarding=1 + +### Enable MPLS Forwarding (with Linux Kernel >= 4.5) + +Edit `/etc/sysctl.conf` and the following lines. Make sure to add a line equal to +`net.mpls.conf.eth0.input` or each interface used with MPLS + + # Enable MPLS Label processing on all interfaces + net.mpls.conf.eth0.input=1 + net.mpls.conf.eth1.input=1 + net.mpls.conf.eth2.input=1 + net.mpls.platform_labels=100000 + +### Add MPLS kernel modules + +Add the following lines to `/etc/modules-load.d/modules.conf`: + + # Load MPLS Kernel Modules + mpls-router + mpls-iptunnel + +**Reboot** or use `sysctl` to apply the same config to the running system From eb651bbceb018fca7873bef03c5b4221a9765b3b Mon Sep 17 00:00:00 2001 From: Martin Winter Date: Thu, 16 Feb 2017 22:55:09 +0700 Subject: [PATCH 22/27] doc: Fixed a few typos on Building Doc's, Changed Tab's to spaces and limited line length to < 80 chars where possible Signed-off-by: Martin Winter --- doc/Building_FRR_on_CentOS6.md | 219 +++++++++++++++--------------- doc/Building_FRR_on_CentOS7.md | 150 ++++++++++---------- doc/Building_FRR_on_Debian8.md | 120 ++++++++-------- doc/Building_FRR_on_Fedora24.md | 115 ++++++++-------- doc/Building_FRR_on_FreeBSD10.md | 119 ++++++++-------- doc/Building_FRR_on_FreeBSD11.md | 119 ++++++++-------- doc/Building_FRR_on_FreeBSD9.md | 115 ++++++++-------- doc/Building_FRR_on_NetBSD6.md | 145 ++++++++++---------- doc/Building_FRR_on_NetBSD7.md | 133 +++++++++--------- doc/Building_FRR_on_OmniOS.md | 154 +++++++++++---------- doc/Building_FRR_on_OpenBSD6.md | 153 +++++++++++---------- doc/Building_FRR_on_Ubuntu1204.md | 186 ++++++++++++------------- doc/Building_FRR_on_Ubuntu1404.md | 120 ++++++++-------- doc/Building_FRR_on_Ubuntu1604.md | 151 ++++++++++---------- 14 files changed, 1029 insertions(+), 970 deletions(-) diff --git a/doc/Building_FRR_on_CentOS6.md b/doc/Building_FRR_on_CentOS6.md index f770aebcf5..ccb07fb2ac 100644 --- a/doc/Building_FRR_on_CentOS6.md +++ b/doc/Building_FRR_on_CentOS6.md @@ -6,148 +6,155 @@ Instructions are tested with `CentOS 6.8` on `x86_64` platform CentOS 6 restrictions: ---------------------- -- PIMd is not supported on `CentOS 6`. Upgrade to `CentOS 7` if PIMd is needed -- MPLS is not supported on `CentOS 6`. MPLS requires Linux Kernel 4.5 or higher - (LDP can be built, but may have limited use without MPLS) +- PIMd is not supported on `CentOS 6`. Upgrade to `CentOS 7` if PIMd is + needed +- MPLS is not supported on `CentOS 6`. MPLS requires Linux Kernel 4.5 or + higher (LDP can be built, but may have limited use without MPLS) Install required packages ------------------------- - + Add packages: - sudo yum install git autoconf automake libtool make gawk readline-devel \ - texinfo net-snmp-devel groff pkgconfig json-c-devel pam-devel \ - flex pytest + sudo yum install git autoconf automake libtool make gawk readline-devel \ + texinfo net-snmp-devel groff pkgconfig json-c-devel pam-devel \ + flex pytest -Install newer version of bison (CentOS 6 package source is too old) from CentOS 7 +Install newer version of bison (CentOS 6 package source is too old) from +CentOS 7 - curl -O http://vault.centos.org/7.0.1406/os/Source/SPackages/bison-2.7-4.el7.src.rpm - rpmbuild --rebuild ./bison-2.7-4.el7.src.rpm - sudo yum install ./rpmbuild/RPMS/x86_64/bison-2.7-4.el6.x86_64.rpm - rm -rf rpmbuild + curl -O http://vault.centos.org/7.0.1406/os/Source/SPackages/bison-2.7-4.el7.src.rpm + rpmbuild --rebuild ./bison-2.7-4.el7.src.rpm + sudo yum install ./rpmbuild/RPMS/x86_64/bison-2.7-4.el6.x86_64.rpm + rm -rf rpmbuild Install newer version of autoconf and automake (Package versions are too old) - curl -O http://ftp.gnu.org/gnu/autoconf/autoconf-2.69.tar.gz - tar xvf autoconf-2.69.tar.gz - cd autoconf-2.69 - ./configure --prefix=/usr - make - sudo make install - cd .. - - curl -O http://ftp.gnu.org/gnu/automake/automake-1.15.tar.gz - tar xvf automake-1.15.tar.gz - cd automake-1.15 - ./configure --prefix=/usr - make - sudo make install - cd .. + curl -O http://ftp.gnu.org/gnu/autoconf/autoconf-2.69.tar.gz + tar xvf autoconf-2.69.tar.gz + cd autoconf-2.69 + ./configure --prefix=/usr + make + sudo make install + cd .. + + curl -O http://ftp.gnu.org/gnu/automake/automake-1.15.tar.gz + tar xvf automake-1.15.tar.gz + cd automake-1.15 + ./configure --prefix=/usr + make + sudo make install + cd .. -Install `Python 2.7` in parallel to default 2.6 (needed for `make check` to run unittests). +Install `Python 2.7` in parallel to default 2.6 (needed for `make check` to +run unittests). Pick correct EPEL based on CentOS version used. Then install current `pytest` - rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm - rpm -ivh https://centos6.iuscommunity.org/ius-release.rpm - yum install python27 python27-pip - pip2.7 install pytest + rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm + rpm -ivh https://centos6.iuscommunity.org/ius-release.rpm + yum install python27 python27-pip + pip2.7 install pytest -Please note that `CentOS 6` needs to keep python pointing to version 2.6 for `yum` to keep -working, so don't create a symlink for python2.7 to python - +Please note that `CentOS 6` needs to keep python pointing to version 2.6 +for `yum` to keep working, so don't create a symlink for python2.7 to python + Get FRR, compile it and install it (from Git) --------------------------------------------- -**This assumes you want to build and install FRR from source and not using any packages** +**This assumes you want to build and install FRR from source and not using +any packages** ### Add frr groups and user - sudo groupadd -g 92 frr - sudo groupadd -r -g 85 frrvt - sudo useradd -u 92 -g 92 -M -r -G frrvt -s /sbin/nologin \ - -c "FRR FreeRangeRouting suite" -d /var/run/frr frr + sudo groupadd -g 92 frr + sudo groupadd -r -g 85 frrvt + sudo useradd -u 92 -g 92 -M -r -G frrvt -s /sbin/nologin \ + -c "FRR FreeRangeRouting suite" -d /var/run/frr frr ### Download Source, configure and compile it -(You may prefer different options on configure statement. These are just an example.) +(You may prefer different options on configure statement. These are just +an example.) -You may want to pay special attention to `/usr/lib64` paths and change them if you are not building on a x86_64 architecture +You may want to pay special attention to `/usr/lib64` paths and change +them if you are not building on a x86_64 architecture - git clone https://github.com/freerangerouting/frr.git frr - cd frr - git checkout stable/2.0 - ./bootstrap.sh - ./configure \ - --sysconfdir=/etc/frr \ - --libdir=/usr/lib64/frr \ - --libexecdir=/usr/lib64/frr \ - --localstatedir=/var/run/frr \ - --disable-pimd \ - --enable-snmp=agentx \ - --enable-multipath=64 \ - --enable-ospfclient=yes \ - --enable-ospfapi=yes \ - --enable-user=frr \ - --enable-group=frr \ - --enable-vty-group=frrvt \ - --enable-rtadv \ - --disable-exampledir \ - --enable-watchfrr \ - --enable-tcp-zebra \ - --enable-fpm \ - --with-pkg-git-version \ - --with-pkg-extra-version=-MyOwnFRRVersion - make - make check PYTHON=/usr/bin/python2.7 - sudo make install + git clone https://github.com/freerangerouting/frr.git frr + cd frr + git checkout stable/2.0 + ./bootstrap.sh + ./configure \ + --sysconfdir=/etc/frr \ + --libdir=/usr/lib64/frr \ + --libexecdir=/usr/lib64/frr \ + --localstatedir=/var/run/frr \ + --disable-pimd \ + --enable-snmp=agentx \ + --enable-multipath=64 \ + --enable-ospfclient=yes \ + --enable-ospfapi=yes \ + --enable-user=frr \ + --enable-group=frr \ + --enable-vty-group=frrvt \ + --enable-rtadv \ + --disable-exampledir \ + --enable-watchfrr \ + --enable-tcp-zebra \ + --enable-fpm \ + --with-pkg-git-version \ + --with-pkg-extra-version=-MyOwnFRRVersion + make + make check PYTHON=/usr/bin/python2.7 + sudo make install ### Create empty FRR configuration files - sudo mkdir /var/log/frr - sudo mkdir /etc/frr - sudo touch /etc/frr/zebra.conf - sudo touch /etc/frr/bgpd.conf - sudo touch /etc/frr/ospfd.conf - sudo touch /etc/frr/ospf6d.conf - sudo touch /etc/frr/isisd.conf - sudo touch /etc/frr/ripd.conf - sudo touch /etc/frr/ripngd.conf - sudo chown -R frr:frr /etc/frr/ - sudo touch /etc/frr/vtysh.conf - sudo chown frr:frrvt /etc/frr/vtysh.conf - sudo chmod 640 /etc/frr/*.conf + sudo mkdir /var/log/frr + sudo mkdir /etc/frr + sudo touch /etc/frr/zebra.conf + sudo touch /etc/frr/bgpd.conf + sudo touch /etc/frr/ospfd.conf + sudo touch /etc/frr/ospf6d.conf + sudo touch /etc/frr/isisd.conf + sudo touch /etc/frr/ripd.conf + sudo touch /etc/frr/ripngd.conf + sudo chown -R frr:frr /etc/frr/ + sudo touch /etc/frr/vtysh.conf + sudo chown frr:frrvt /etc/frr/vtysh.conf + sudo chmod 640 /etc/frr/*.conf ### Enable IP & IPv6 forwarding -Edit `/etc/sysctl.conf` and set the following values (ignore the other settings) +Edit `/etc/sysctl.conf` and set the following values (ignore the other +settings) - # Controls IP packet forwarding - net.ipv4.ip_forward = 1 - net.ipv6.conf.all.forwarding=1 + # Controls IP packet forwarding + net.ipv4.ip_forward = 1 + net.ipv6.conf.all.forwarding=1 - # Controls source route verification - net.ipv4.conf.default.rp_filter = 0 + # Controls source route verification + net.ipv4.conf.default.rp_filter = 0 **Reboot** or use `sysctl` to apply the same config to the running system ### Add init.d startup files - sudo cp redhat/bgpd.init /etc/init.d/bgpd - sudo cp redhat/isisd.init /etc/init.d/isisd - sudo cp redhat/ospfd.init /etc/init.d/ospfd - sudo cp redhat/ospf6d.init /etc/init.d/ospf6d - sudo cp redhat/ripngd.init /etc/init.d/ripngd - sudo cp redhat/ripd.init /etc/init.d/ripd - sudo cp redhat/zebra.init /etc/init.d/zebra - sudo chkconfig --add zebra - sudo chkconfig --add ripd - sudo chkconfig --add ripngd - sudo chkconfig --add ospf6d - sudo chkconfig --add ospfd - sudo chkconfig --add bgpd - sudo chkconfig --add isisd + sudo cp redhat/bgpd.init /etc/init.d/bgpd + sudo cp redhat/isisd.init /etc/init.d/isisd + sudo cp redhat/ospfd.init /etc/init.d/ospfd + sudo cp redhat/ospf6d.init /etc/init.d/ospf6d + sudo cp redhat/ripngd.init /etc/init.d/ripngd + sudo cp redhat/ripd.init /etc/init.d/ripd + sudo cp redhat/zebra.init /etc/init.d/zebra + sudo chkconfig --add zebra + sudo chkconfig --add ripd + sudo chkconfig --add ripngd + sudo chkconfig --add ospf6d + sudo chkconfig --add ospfd + sudo chkconfig --add bgpd + sudo chkconfig --add isisd ### Enable required daemons at startup Only enable zebra and the daemons which are needed for your setup - sudo chkconfig zebra on - sudo chkconfig ospfd on - sudo chkconfig bgpd on - [...] etc (as needed) + sudo chkconfig zebra on + sudo chkconfig ospfd on + sudo chkconfig bgpd on + [...] etc (as needed) diff --git a/doc/Building_FRR_on_CentOS7.md b/doc/Building_FRR_on_CentOS7.md index 36e50e4429..cd10a91ed7 100644 --- a/doc/Building_FRR_on_CentOS7.md +++ b/doc/Building_FRR_on_CentOS7.md @@ -10,76 +10,80 @@ CentOS 7 restrictions: Install required packages ------------------------- - + Add packages: - sudo yum install git autoconf automake libtool make gawk readline-devel \ - texinfo net-snmp-devel groff pkgconfig json-c-devel pam-devel \ - bison flex pytest + sudo yum install git autoconf automake libtool make gawk readline-devel \ + texinfo net-snmp-devel groff pkgconfig json-c-devel pam-devel \ + bison flex pytest Get FRR, compile it and install it (from Git) --------------------------------------------- -**This assumes you want to build and install FRR from source and not using any packages** +**This assumes you want to build and install FRR from source and not using +any packages** ### Add frr groups and user - sudo groupadd -g 92 frr - sudo groupadd -r -g 85 frrvt - sudo useradd -u 92 -g 92 -M -r -G frrvt -s /sbin/nologin \ - -c "FRR FreeRangeRouting suite" -d /var/run/frr frr + sudo groupadd -g 92 frr + sudo groupadd -r -g 85 frrvt + sudo useradd -u 92 -g 92 -M -r -G frrvt -s /sbin/nologin \ + -c "FRR FreeRangeRouting suite" -d /var/run/frr frr ### Download Source, configure and compile it -(You may prefer different options on configure statement. These are just an example.) +(You may prefer different options on configure statement. These are just +an example.) -You may want to pay special attention to `/usr/lib64` paths and change them if you are not building on a x86_64 architecture +You may want to pay special attention to `/usr/lib64` paths and change +them if you are not building on a x86_64 architecture - git clone https://github.com/freerangerouting/frr.git frr - cd frr - git checkout stable/2.0 - ./bootstrap.sh - ./configure \ - --sysconfdir=/etc/frr \ - --libdir=/usr/lib64/frr \ - --libexecdir=/usr/lib64/frr \ - --localstatedir=/var/run/frr \ - --enable-snmp=agentx \ - --enable-multipath=64 \ - --enable-ospfclient=yes \ - --enable-ospfapi=yes \ - --enable-user=frr \ - --enable-group=frr \ - --enable-vty-group=frrvt \ - --enable-rtadv \ - --disable-exampledir \ - --enable-watchfrr \ - --enable-tcp-zebra \ - --enable-fpm \ - --with-pkg-git-version \ - --with-pkg-extra-version=-MyOwnFRRVersion - make - make check - sudo make install + git clone https://github.com/freerangerouting/frr.git frr + cd frr + git checkout stable/2.0 + ./bootstrap.sh + ./configure \ + --sysconfdir=/etc/frr \ + --libdir=/usr/lib64/frr \ + --libexecdir=/usr/lib64/frr \ + --localstatedir=/var/run/frr \ + --enable-snmp=agentx \ + --enable-multipath=64 \ + --enable-ospfclient=yes \ + --enable-ospfapi=yes \ + --enable-user=frr \ + --enable-group=frr \ + --enable-vty-group=frrvt \ + --enable-rtadv \ + --disable-exampledir \ + --enable-watchfrr \ + --enable-tcp-zebra \ + --enable-fpm \ + --with-pkg-git-version \ + --with-pkg-extra-version=-MyOwnFRRVersion + make + make check + sudo make install ### Create empty FRR configuration files - sudo mkdir /var/log/frr - sudo mkdir /etc/frr - sudo touch /etc/frr/zebra.conf - sudo touch /etc/frr/bgpd.conf - sudo touch /etc/frr/ospfd.conf - sudo touch /etc/frr/ospf6d.conf - sudo touch /etc/frr/isisd.conf - sudo touch /etc/frr/ripd.conf - sudo touch /etc/frr/ripngd.conf - sudo touch /etc/frr/pimd.conf - sudo chown -R frr:frr /etc/frr/ - sudo touch /etc/frr/vtysh.conf - sudo chown frr:frrvt /etc/frr/vtysh.conf - sudo chmod 640 /etc/frr/*.conf + sudo mkdir /var/log/frr + sudo mkdir /etc/frr + sudo touch /etc/frr/zebra.conf + sudo touch /etc/frr/bgpd.conf + sudo touch /etc/frr/ospfd.conf + sudo touch /etc/frr/ospf6d.conf + sudo touch /etc/frr/isisd.conf + sudo touch /etc/frr/ripd.conf + sudo touch /etc/frr/ripngd.conf + sudo touch /etc/frr/pimd.conf + sudo chown -R frr:frr /etc/frr/ + sudo touch /etc/frr/vtysh.conf + sudo chown frr:frrvt /etc/frr/vtysh.conf + sudo chmod 640 /etc/frr/*.conf ### Enable IP & IPv6 forwarding -Create a new file `/etc/sysctl.d/90-routing-sysctl.conf` with the following content: +Create a new file `/etc/sysctl.d/90-routing-sysctl.conf` with the +following content: # Sysctl for routing # @@ -90,30 +94,30 @@ Create a new file `/etc/sysctl.d/90-routing-sysctl.conf` with the following cont **Reboot** or use `sysctl` to apply the same config to the running system ### Install Service files - sudo install -p -m 644 redhat/zebra.service /usr/lib/systemd/system/zebra.service - sudo install -p -m 644 redhat/isisd.service /usr/lib/systemd/system/isisd.service - sudo install -p -m 644 redhat/ripd.service /usr/lib/systemd/system/ripd.service - sudo install -p -m 644 redhat/ospfd.service /usr/lib/systemd/system/ospfd.service - sudo install -p -m 644 redhat/bgpd.service /usr/lib/systemd/system/bgpd.service - sudo install -p -m 644 redhat/ospf6d.service /usr/lib/systemd/system/ospf6d.service - sudo install -p -m 644 redhat/ripngd.service /usr/lib/systemd/system/ripngd.service - sudo install -p -m 644 redhat/pimd.service /usr/lib/systemd/system/pimd.service - sudo install -p -m 644 redhat/frr.sysconfig /etc/sysconfig/frr - sudo install -p -m 644 redhat/frr.logrotate /etc/logrotate.d/frr + sudo install -p -m 644 redhat/zebra.service /usr/lib/systemd/system/zebra.service + sudo install -p -m 644 redhat/isisd.service /usr/lib/systemd/system/isisd.service + sudo install -p -m 644 redhat/ripd.service /usr/lib/systemd/system/ripd.service + sudo install -p -m 644 redhat/ospfd.service /usr/lib/systemd/system/ospfd.service + sudo install -p -m 644 redhat/bgpd.service /usr/lib/systemd/system/bgpd.service + sudo install -p -m 644 redhat/ospf6d.service /usr/lib/systemd/system/ospf6d.service + sudo install -p -m 644 redhat/ripngd.service /usr/lib/systemd/system/ripngd.service + sudo install -p -m 644 redhat/pimd.service /usr/lib/systemd/system/pimd.service + sudo install -p -m 644 redhat/frr.sysconfig /etc/sysconfig/frr + sudo install -p -m 644 redhat/frr.logrotate /etc/logrotate.d/frr ### Register the systemd files - sudo systemctl preset zebra.service - sudo systemctl preset ripd.service - sudo systemctl preset ospfd.service - sudo systemctl preset bgpd.service - sudo systemctl preset ospf6d.service - sudo systemctl preset ripngd.service - sudo systemctl preset pimd.service + sudo systemctl preset zebra.service + sudo systemctl preset ripd.service + sudo systemctl preset ospfd.service + sudo systemctl preset bgpd.service + sudo systemctl preset ospf6d.service + sudo systemctl preset ripngd.service + sudo systemctl preset pimd.service ### Enable required daemons at startup Only enable zebra and the daemons which are needed for your setup - sudo systemctl enable zebra - sudo systemctl enable ospfd - sudo systemctl enable bgpd - [...] etc (as needed) + sudo systemctl enable zebra + sudo systemctl enable ospfd + sudo systemctl enable bgpd + [...] etc (as needed) diff --git a/doc/Building_FRR_on_Debian8.md b/doc/Building_FRR_on_Debian8.md index 098a65d620..902f8c623a 100644 --- a/doc/Building_FRR_on_Debian8.md +++ b/doc/Building_FRR_on_Debian8.md @@ -10,85 +10,89 @@ Debian 8 restrictions: Install required packages ------------------------- - + Add packages: - sudo apt-get install git autoconf automake libtool make gawk libreadline-dev \ - texinfo libjson-c-dev pkg-config bison flex python-pip + sudo apt-get install git autoconf automake libtool make gawk \ + libreadline-dev texinfo libjson-c-dev pkg-config bison flex \ + python-pip -Install newer pytest (>3.0) from pip +Install newer pytest (>3.0) from pip + + sudo pip install pytest - sudo pip install pytest - Get FRR, compile it and install it (from Git) --------------------------------------------- -**This assumes you want to build and install FRR from source and not using any packages** +**This assumes you want to build and install FRR from source and not using +any packages** ### Add frr groups and user - sudo addgroup --system --gid 92 frr - sudo addgroup --system --gid 85 frrvty - sudo adduser --system --ingroup frr --groups frrvty --home /var/run/frr/ \ + sudo addgroup --system --gid 92 frr + sudo addgroup --system --gid 85 frrvty + sudo adduser --system --ingroup frr --groups frrvty --home /var/run/frr/ \ --gecos "FRR FreeRangeRouting suite" --shell /bin/false frr sudo usermode ### Download Source, configure and compile it -(You may prefer different options on configure statement. These are just an example.) +(You may prefer different options on configure statement. These are just +an example.) - git clone https://github.com/freerangerouting/frr.git frr - cd frr - git checkout stable/2.0 - ./bootstrap.sh - ./configure \ - --enable-exampledir=/usr/share/doc/frr/examples/ \ - --localstatedir=/var/run/frr \ - --sbindir=/usr/lib/frr \ - --sysconfdir=/etc/frr \ - --enable-vtysh \ - --enable-isisd \ - --enable-pimd \ - --enable-watchfrr \ - --enable-ospfclient=yes \ - --enable-ospfapi=yes \ - --enable-multipath=64 \ - --enable-user=frr \ - --enable-group=frr \ - --enable-vty-group=frrvty \ - --enable-configfile-mask=0640 \ - --enable-logfile-mask=0640 \ - --enable-rtadv \ - --enable-tcp-zebra \ - --enable-fpm \ - --with-pkg-git-version \ - --with-pkg-extra-version=-MyOwnFRRVersion - make - make check - sudo make install + git clone https://github.com/freerangerouting/frr.git frr + cd frr + git checkout stable/2.0 + ./bootstrap.sh + ./configure \ + --enable-exampledir=/usr/share/doc/frr/examples/ \ + --localstatedir=/var/run/frr \ + --sbindir=/usr/lib/frr \ + --sysconfdir=/etc/frr \ + --enable-vtysh \ + --enable-isisd \ + --enable-pimd \ + --enable-watchfrr \ + --enable-ospfclient=yes \ + --enable-ospfapi=yes \ + --enable-multipath=64 \ + --enable-user=frr \ + --enable-group=frr \ + --enable-vty-group=frrvty \ + --enable-configfile-mask=0640 \ + --enable-logfile-mask=0640 \ + --enable-rtadv \ + --enable-tcp-zebra \ + --enable-fpm \ + --with-pkg-git-version \ + --with-pkg-extra-version=-MyOwnFRRVersion + make + make check + sudo make install ### Create empty FRR configuration files - sudo install -m 755 -o frr -g frr -d /var/log/frr - sudo install -m 775 -o frr -g frrvty -d /etc/frr - sudo install -m 640 -o frr -g frr /dev/null /etc/frr/zebra.conf - sudo install -m 640 -o frr -g frr /dev/null /etc/frr/bgpd.conf - sudo install -m 640 -o frr -g frr /dev/null /etc/frr/ospfd.conf - sudo install -m 640 -o frr -g frr /dev/null /etc/frr/ospf6d.conf - sudo install -m 640 -o frr -g frr /dev/null /etc/frr/isisd.conf - sudo install -m 640 -o frr -g frr /dev/null /etc/frr/ripd.conf - sudo install -m 640 -o frr -g frr /dev/null /etc/frr/ripngd.conf - sudo install -m 640 -o frr -g frr /dev/null /etc/frr/pimd.conf - sudo install -m 640 -o frr -g frrvty /dev/null /etc/frr/vtysh.conf + sudo install -m 755 -o frr -g frr -d /var/log/frr + sudo install -m 775 -o frr -g frrvty -d /etc/frr + sudo install -m 640 -o frr -g frr /dev/null /etc/frr/zebra.conf + sudo install -m 640 -o frr -g frr /dev/null /etc/frr/bgpd.conf + sudo install -m 640 -o frr -g frr /dev/null /etc/frr/ospfd.conf + sudo install -m 640 -o frr -g frr /dev/null /etc/frr/ospf6d.conf + sudo install -m 640 -o frr -g frr /dev/null /etc/frr/isisd.conf + sudo install -m 640 -o frr -g frr /dev/null /etc/frr/ripd.conf + sudo install -m 640 -o frr -g frr /dev/null /etc/frr/ripngd.conf + sudo install -m 640 -o frr -g frr /dev/null /etc/frr/pimd.conf + sudo install -m 640 -o frr -g frrvty /dev/null /etc/frr/vtysh.conf ### Enable IP & IPv6 forwarding -Edit `/etc/sysctl.conf` and uncomment the following values (ignore the other settings) +Edit `/etc/sysctl.conf` and uncomment the following values (ignore the +other settings) - # Uncomment the next line to enable packet forwarding for IPv4 - net.ipv4.ip_forward=1 + # Uncomment the next line to enable packet forwarding for IPv4 + net.ipv4.ip_forward=1 - # Uncomment the next line to enable packet forwarding for IPv6 - # Enabling this option disables Stateless Address Autoconfiguration - # based on Router Advertisements for this host - net.ipv6.conf.all.forwarding=1 + # Uncomment the next line to enable packet forwarding for IPv6 + # Enabling this option disables Stateless Address Autoconfiguration + # based on Router Advertisements for this host + net.ipv6.conf.all.forwarding=1 **Reboot** or use `sysctl` to apply the same config to the running system diff --git a/doc/Building_FRR_on_Fedora24.md b/doc/Building_FRR_on_Fedora24.md index 784449d736..9617afc733 100644 --- a/doc/Building_FRR_on_Fedora24.md +++ b/doc/Building_FRR_on_Fedora24.md @@ -3,17 +3,18 @@ Building FRR on Fedora 24 from Git Source Install required packages ------------------------- - + Add packages: - sudo dnf install git autoconf automake libtool make gawk readline-devel \ - texinfo net-snmp-devel groff pkgconfig json-c-devel pam-devel \ - perl-XML-LibXML pytest + sudo dnf install git autoconf automake libtool make gawk \ + readline-devel texinfo net-snmp-devel groff pkgconfig \ + json-c-devel pam-devel perl-XML-LibXML pytest Get FRR, compile it and install it (from Git) --------------------------------------------- -**This assumes you want to build and install FRR from source and not using any packages** +**This assumes you want to build and install FRR from source and not +using any packages** ### Add frr groups and user @@ -23,77 +24,81 @@ Get FRR, compile it and install it (from Git) -c "FRR FreeRangeRouting suite" -d /var/run/frr frr ### Download Source, configure and compile it -(You may prefer different options on configure statement. These are just an example.) +(You may prefer different options on configure statement. These are just +an example.) -You may want to pay special attention to `/usr/lib64` paths and chenge them if you are not building on a x86_64 architecture +You may want to pay special attention to `/usr/lib64` paths and change +them if you are not building on a x86_64 architecture - git clone https://github.com/freerangerouting/frr.git frr - cd frr - git checkout stable/2.0 + git clone https://github.com/freerangerouting/frr.git frr + cd frr + git checkout stable/2.0 ./bootstrap.sh ./configure \ - --sysconfdir=/etc/frr \ - --libdir=/usr/lib64/frr \ - --libexecdir=/usr/lib64/frr \ - --localstatedir=/var/run/frr \ - --enable-pimd \ - --enable-snmp=agentx \ - --enable-multipath=64 \ - --enable-ospfclient=yes \ - --enable-ospfapi=yes \ - --enable-user=frr \ - --enable-group=frr \ - --enable-vty-group=frrvt \ - --enable-rtadv \ - --disable-exampledir \ - --enable-watchfrr \ - --enable-tcp-zebra \ - --enable-fpm \ - --with-pkg-git-version \ - --with-pkg-extra-version=-MyOwnFRRVersion + --sysconfdir=/etc/frr \ + --libdir=/usr/lib64/frr \ + --libexecdir=/usr/lib64/frr \ + --localstatedir=/var/run/frr \ + --enable-pimd \ + --enable-snmp=agentx \ + --enable-multipath=64 \ + --enable-ospfclient=yes \ + --enable-ospfapi=yes \ + --enable-user=frr \ + --enable-group=frr \ + --enable-vty-group=frrvt \ + --enable-rtadv \ + --disable-exampledir \ + --enable-watchfrr \ + --enable-tcp-zebra \ + --enable-fpm \ + --with-pkg-git-version \ + --with-pkg-extra-version=-MyOwnFRRVersion make make check sudo make install ### Create empty FRR configuration files - sudo mkdir /var/log/frr - sudo mkdir /etc/frr - sudo touch /etc/frr/zebra.conf - sudo touch /etc/frr/bgpd.conf - sudo touch /etc/frr/ospfd.conf - sudo touch /etc/frr/ospf6d.conf - sudo touch /etc/frr/isisd.conf - sudo touch /etc/frr/ripd.conf - sudo touch /etc/frr/ripngd.conf - sudo touch /etc/frr/pimd.conf - sudo touch /etc/frr/ldpd.conf - sudo chown -R frr:frr /etc/frr/ - sudo touch /etc/frr/vtysh.conf - sudo chown frr:frrvt /etc/frr/vtysh.conf - sudo chmod 640 /etc/frr/*.conf + sudo mkdir /var/log/frr + sudo mkdir /etc/frr + sudo touch /etc/frr/zebra.conf + sudo touch /etc/frr/bgpd.conf + sudo touch /etc/frr/ospfd.conf + sudo touch /etc/frr/ospf6d.conf + sudo touch /etc/frr/isisd.conf + sudo touch /etc/frr/ripd.conf + sudo touch /etc/frr/ripngd.conf + sudo touch /etc/frr/pimd.conf + sudo touch /etc/frr/ldpd.conf + sudo chown -R frr:frr /etc/frr/ + sudo touch /etc/frr/vtysh.conf + sudo chown frr:frrvt /etc/frr/vtysh.conf + sudo chmod 640 /etc/frr/*.conf ### Enable IP & IPv6 forwarding (and MPLS) -Create a new file `/etc/sysctl.d/90-routing-sysctl.conf` with the following content: -(Please make sure to list all interfaces with required MPLS similar to `net.mpls.conf.eth0.input=1`) +Create a new file `/etc/sysctl.d/90-routing-sysctl.conf` with the +following content: +(Please make sure to list all interfaces with required MPLS similar +to `net.mpls.conf.eth0.input=1`) # Sysctl for routing # # Routing: We need to forward packets net.ipv4.conf.all.forwarding=1 net.ipv6.conf.all.forwarding=1 - # - # Enable MPLS Label processing on all interfaces - net.mpls.conf.eth0.input=1 - net.mpls.conf.eth1.input=1 - net.mpls.conf.eth2.input=1 - net.mpls.platform_labels=100000 + # + # Enable MPLS Label processing on all interfaces + net.mpls.conf.eth0.input=1 + net.mpls.conf.eth1.input=1 + net.mpls.conf.eth2.input=1 + net.mpls.platform_labels=100000 Create a new file `/etc/modules-load.d/mpls.conf` with the following content: - # Load MPLS Kernel Modules - mpls-router - mpls-iptunnel + # Load MPLS Kernel Modules + mpls-router + mpls-iptunnel **Reboot** or use `sysctl` to apply the same config to the running system diff --git a/doc/Building_FRR_on_FreeBSD10.md b/doc/Building_FRR_on_FreeBSD10.md index 4cd0edd1a0..696b7d5d2e 100644 --- a/doc/Building_FRR_on_FreeBSD10.md +++ b/doc/Building_FRR_on_FreeBSD10.md @@ -12,80 +12,85 @@ Install required packages ------------------------- Add packages: -(Allow the install of the package managment tool if this is first package install and asked) +(Allow the install of the package managment tool if this is first package +install and asked) - pkg install git autoconf automake libtool gmake gawk json-c pkgconf \ - bison flex py27-pytest + pkg install git autoconf automake libtool gmake gawk json-c pkgconf \ + bison flex py27-pytest -Make sure there is no /usr/bin/flex preinstalled (and use the newly installed in /usr/local/bin): -(FreeBSD frequently provides a older flex as part of the base OS whcih takes preference in path) +Make sure there is no /usr/bin/flex preinstalled (and use the newly +installed in /usr/local/bin): +(FreeBSD frequently provides a older flex as part of the base OS which +takes preference in path) + + rm -f /usr/bin/flex - rm -f /usr/bin/flex - Get FRR, compile it and install it (from Git) --------------------------------------------- -**This assumes you want to build and install FRR from source and not using any packages** +**This assumes you want to build and install FRR from source and not +using any packages** ### Add frr group and user - pw groupadd frr -g 101 - pw groupadd frrvty -g 102 - pw adduser frr -g 101 -u 101 -G 102 -c "FRR suite" \ - -d /usr/local/etc/frr -s /usr/sbin/nologin + pw groupadd frr -g 101 + pw groupadd frrvty -g 102 + pw adduser frr -g 101 -u 101 -G 102 -c "FRR suite" \ + -d /usr/local/etc/frr -s /usr/sbin/nologin -(You may prefer different options on configure statement. These are just an example) +(You may prefer different options on configure statement. These are just +an example) - git clone https://github.com/freerangerouting/frr.git frr - cd frr - git checkout stable/2.0 - ./bootstrap.sh - export MAKE=gmake - export LDFLAGS="-L/usr/local/lib" - export CPPFLAGS="-I/usr/local/include" - ./configure \ - --sysconfdir=/usr/local/etc/frr \ - --enable-pkgsrcrcdir=/usr/pkg/share/examples/rc.d \ - --localstatedir=/var/run/frr \ - --prefix=/usr/local \ - --enable-ospfclient=yes \ - --enable-ospfapi=yes \ - --enable-multipath=64 \ - --enable-user=frr \ - --enable-group=frr \ - --enable-vty-group=frrvty \ - --enable-configfile-mask=0640 \ - --enable-logfile-mask=0640 \ - --enable-rtadv \ - --enable-tcp-zebra \ - --enable-fpm \ - --with-pkg-git-version \ - --with-pkg-extra-version=-MyOwnFRRVersion - gmake - gmake check - sudo gmake install + git clone https://github.com/freerangerouting/frr.git frr + cd frr + git checkout stable/2.0 + ./bootstrap.sh + export MAKE=gmake + export LDFLAGS="-L/usr/local/lib" + export CPPFLAGS="-I/usr/local/include" + ./configure \ + --sysconfdir=/usr/local/etc/frr \ + --enable-pkgsrcrcdir=/usr/pkg/share/examples/rc.d \ + --localstatedir=/var/run/frr \ + --prefix=/usr/local \ + --enable-ospfclient=yes \ + --enable-ospfapi=yes \ + --enable-multipath=64 \ + --enable-user=frr \ + --enable-group=frr \ + --enable-vty-group=frrvty \ + --enable-configfile-mask=0640 \ + --enable-logfile-mask=0640 \ + --enable-rtadv \ + --enable-tcp-zebra \ + --enable-fpm \ + --with-pkg-git-version \ + --with-pkg-extra-version=-MyOwnFRRVersion + gmake + gmake check + sudo gmake install ### Create empty FRR configuration files - sudo mkdir /usr/local/etc/frr - sudo touch /usr/local/etc/frr/zebra.conf - sudo touch /usr/local/etc/frr/bgpd.conf - sudo touch /usr/local/etc/frr/ospfd.conf - sudo touch /usr/local/etc/frr/ospf6d.conf - sudo touch /usr/local/etc/frr/isisd.conf - sudo touch /usr/local/etc/frr/ripd.conf - sudo touch /usr/local/etc/frr/ripngd.conf - sudo touch /usr/local/etc/frr/pimd.conf - sudo chown -R frr:frr /usr/local/etc/frr - sudo touch /usr/local/etc/frr/vtysh.conf - sudo chown frr:frrvty /usr/local/etc/frr/vtysh.conf - sudo chmod 640 /usr/local/etc/frr/*.conf + sudo mkdir /usr/local/etc/frr + sudo touch /usr/local/etc/frr/zebra.conf + sudo touch /usr/local/etc/frr/bgpd.conf + sudo touch /usr/local/etc/frr/ospfd.conf + sudo touch /usr/local/etc/frr/ospf6d.conf + sudo touch /usr/local/etc/frr/isisd.conf + sudo touch /usr/local/etc/frr/ripd.conf + sudo touch /usr/local/etc/frr/ripngd.conf + sudo touch /usr/local/etc/frr/pimd.conf + sudo chown -R frr:frr /usr/local/etc/frr + sudo touch /usr/local/etc/frr/vtysh.conf + sudo chown frr:frrvty /usr/local/etc/frr/vtysh.conf + sudo chmod 640 /usr/local/etc/frr/*.conf ### Enable IP & IPv6 forwarding Add the following lines to the end of `/etc/sysctl.conf`: - # Routing: We need to forward packets - net.inet.ip.forwarding=1 - net.inet6.ip6.forwarding=1 + # Routing: We need to forward packets + net.inet.ip.forwarding=1 + net.inet6.ip6.forwarding=1 **Reboot** or use `sysctl` to apply the same config to the running system diff --git a/doc/Building_FRR_on_FreeBSD11.md b/doc/Building_FRR_on_FreeBSD11.md index fec06bc092..d0b8a7bf88 100644 --- a/doc/Building_FRR_on_FreeBSD11.md +++ b/doc/Building_FRR_on_FreeBSD11.md @@ -12,80 +12,85 @@ Install required packages ------------------------- Add packages: -(Allow the install of the package managment tool if this is first package install and asked) +(Allow the install of the package managment tool if this is first package +install and asked) - pkg install git autoconf automake libtool gmake gawk json-c pkgconf \ - bison flex py27-pytest + pkg install git autoconf automake libtool gmake gawk json-c pkgconf \ + bison flex py27-pytest -Make sure there is no /usr/bin/flex preinstalled (and use the newly installed in /usr/local/bin): -(FreeBSD frequently provides a older flex as part of the base OS whcih takes preference in path) +Make sure there is no /usr/bin/flex preinstalled (and use the newly +installed in /usr/local/bin): +(FreeBSD frequently provides a older flex as part of the base OS which +takes preference in path) + + rm -f /usr/bin/flex - rm -f /usr/bin/flex - Get FRR, compile it and install it (from Git) --------------------------------------------- -**This assumes you want to build and install FRR from source and not using any packages** +**This assumes you want to build and install FRR from source and not +using any packages** ### Add frr group and user - pw groupadd frr -g 101 - pw groupadd frrvty -g 102 - pw adduser frr -g 101 -u 101 -G 102 -c "FRR suite" \ - -d /usr/local/etc/frr -s /usr/sbin/nologin + pw groupadd frr -g 101 + pw groupadd frrvty -g 102 + pw adduser frr -g 101 -u 101 -G 102 -c "FRR suite" \ + -d /usr/local/etc/frr -s /usr/sbin/nologin -(You may prefer different options on configure statement. These are just an example) +(You may prefer different options on configure statement. These are just +an example) - git clone https://github.com/freerangerouting/frr.git frr - cd frr - git checkout stable/2.0 - ./bootstrap.sh - export MAKE=gmake - export LDFLAGS="-L/usr/local/lib" - export CPPFLAGS="-I/usr/local/include" - ./configure \ - --sysconfdir=/usr/local/etc/frr \ - --enable-pkgsrcrcdir=/usr/pkg/share/examples/rc.d \ - --localstatedir=/var/run/frr \ - --prefix=/usr/local \ - --enable-ospfclient=yes \ - --enable-ospfapi=yes \ - --enable-multipath=64 \ - --enable-user=frr \ - --enable-group=frr \ - --enable-vty-group=frrvty \ - --enable-configfile-mask=0640 \ - --enable-logfile-mask=0640 \ - --enable-rtadv \ - --enable-tcp-zebra \ - --enable-fpm \ - --with-pkg-git-version \ - --with-pkg-extra-version=-MyOwnFRRVersion - gmake - gmake check - sudo gmake install + git clone https://github.com/freerangerouting/frr.git frr + cd frr + git checkout stable/2.0 + ./bootstrap.sh + export MAKE=gmake + export LDFLAGS="-L/usr/local/lib" + export CPPFLAGS="-I/usr/local/include" + ./configure \ + --sysconfdir=/usr/local/etc/frr \ + --enable-pkgsrcrcdir=/usr/pkg/share/examples/rc.d \ + --localstatedir=/var/run/frr \ + --prefix=/usr/local \ + --enable-ospfclient=yes \ + --enable-ospfapi=yes \ + --enable-multipath=64 \ + --enable-user=frr \ + --enable-group=frr \ + --enable-vty-group=frrvty \ + --enable-configfile-mask=0640 \ + --enable-logfile-mask=0640 \ + --enable-rtadv \ + --enable-tcp-zebra \ + --enable-fpm \ + --with-pkg-git-version \ + --with-pkg-extra-version=-MyOwnFRRVersion + gmake + gmake check + sudo gmake install ### Create empty FRR configuration files - sudo mkdir /usr/local/etc/frr - sudo touch /usr/local/etc/frr/zebra.conf - sudo touch /usr/local/etc/frr/bgpd.conf - sudo touch /usr/local/etc/frr/ospfd.conf - sudo touch /usr/local/etc/frr/ospf6d.conf - sudo touch /usr/local/etc/frr/isisd.conf - sudo touch /usr/local/etc/frr/ripd.conf - sudo touch /usr/local/etc/frr/ripngd.conf - sudo touch /usr/local/etc/frr/pimd.conf - sudo chown -R frr:frr /usr/local/etc/frr - sudo touch /usr/local/etc/frr/vtysh.conf - sudo chown frr:frrvty /usr/local/etc/frr/vtysh.conf - sudo chmod 640 /usr/local/etc/frr/*.conf + sudo mkdir /usr/local/etc/frr + sudo touch /usr/local/etc/frr/zebra.conf + sudo touch /usr/local/etc/frr/bgpd.conf + sudo touch /usr/local/etc/frr/ospfd.conf + sudo touch /usr/local/etc/frr/ospf6d.conf + sudo touch /usr/local/etc/frr/isisd.conf + sudo touch /usr/local/etc/frr/ripd.conf + sudo touch /usr/local/etc/frr/ripngd.conf + sudo touch /usr/local/etc/frr/pimd.conf + sudo chown -R frr:frr /usr/local/etc/frr + sudo touch /usr/local/etc/frr/vtysh.conf + sudo chown frr:frrvty /usr/local/etc/frr/vtysh.conf + sudo chmod 640 /usr/local/etc/frr/*.conf ### Enable IP & IPv6 forwarding Add the following lines to the end of `/etc/sysctl.conf`: - # Routing: We need to forward packets - net.inet.ip.forwarding=1 - net.inet6.ip6.forwarding=1 + # Routing: We need to forward packets + net.inet.ip.forwarding=1 + net.inet6.ip6.forwarding=1 **Reboot** or use `sysctl` to apply the same config to the running system diff --git a/doc/Building_FRR_on_FreeBSD9.md b/doc/Building_FRR_on_FreeBSD9.md index 37fdd92b15..d470d0046a 100644 --- a/doc/Building_FRR_on_FreeBSD9.md +++ b/doc/Building_FRR_on_FreeBSD9.md @@ -12,80 +12,85 @@ Install required packages ------------------------- Add packages: -(Allow the install of the package managment tool if this is first package install and asked) +(Allow the install of the package managment tool if this is first package +install and asked) pkg install -y git autoconf automake libtool gmake gawk \ pkgconf texinfo json-c bison flex py27-pytest -Make sure there is no /usr/bin/flex preinstalled (and use the newly installed in /usr/local/bin): -(FreeBSD frequently provides a older flex as part of the base OS whcih takes preference in path) +Make sure there is no /usr/bin/flex preinstalled (and use the newly +installed in /usr/local/bin): +(FreeBSD frequently provides a older flex as part of the base OS which +takes preference in path) + + rm -f /usr/bin/flex - rm -f /usr/bin/flex - Get FRR, compile it and install it (from Git) --------------------------------------------- -**This assumes you want to build and install FRR from source and not using any packages** +**This assumes you want to build and install FRR from source and not +using any packages** ### Add frr group and user - pw groupadd frr -g 101 - pw groupadd frrvty -g 102 - pw adduser frr -g 101 -u 101 -G 102 -c "FRR suite" \ - -d /usr/local/etc/frr -s /usr/sbin/nologin + pw groupadd frr -g 101 + pw groupadd frrvty -g 102 + pw adduser frr -g 101 -u 101 -G 102 -c "FRR suite" \ + -d /usr/local/etc/frr -s /usr/sbin/nologin -(You may prefer different options on configure statement. These are just an example) +(You may prefer different options on configure statement. These are just +an example) - git clone https://github.com/freerangerouting/frr.git frr - cd frr - git checkout stable/2.0 - ./bootstrap.sh - export MAKE=gmake - export LDFLAGS="-L/usr/local/lib" - export CPPFLAGS="-I/usr/local/include" - ./configure \ - --sysconfdir=/usr/local/etc/frr \ - --enable-pkgsrcrcdir=/usr/pkg/share/examples/rc.d \ - --localstatedir=/var/run/frr \ - --prefix=/usr/local \ - --enable-ospfclient=yes \ - --enable-ospfapi=yes \ - --enable-multipath=64 \ - --enable-user=frr \ - --enable-group=frr \ - --enable-vty-group=frrvty \ - --enable-configfile-mask=0640 \ - --enable-logfile-mask=0640 \ - --enable-rtadv \ - --enable-tcp-zebra \ - --enable-fpm \ - --with-pkg-git-version \ - --with-pkg-extra-version=-MyOwnFRRVersion - gmake - gmake check - sudo gmake install + git clone https://github.com/freerangerouting/frr.git frr + cd frr + git checkout stable/2.0 + ./bootstrap.sh + export MAKE=gmake + export LDFLAGS="-L/usr/local/lib" + export CPPFLAGS="-I/usr/local/include" + ./configure \ + --sysconfdir=/usr/local/etc/frr \ + --enable-pkgsrcrcdir=/usr/pkg/share/examples/rc.d \ + --localstatedir=/var/run/frr \ + --prefix=/usr/local \ + --enable-ospfclient=yes \ + --enable-ospfapi=yes \ + --enable-multipath=64 \ + --enable-user=frr \ + --enable-group=frr \ + --enable-vty-group=frrvty \ + --enable-configfile-mask=0640 \ + --enable-logfile-mask=0640 \ + --enable-rtadv \ + --enable-tcp-zebra \ + --enable-fpm \ + --with-pkg-git-version \ + --with-pkg-extra-version=-MyOwnFRRVersion + gmake + gmake check + sudo gmake install ### Create empty FRR configuration files - sudo mkdir /usr/local/etc/frr - sudo touch /usr/local/etc/frr/zebra.conf - sudo touch /usr/local/etc/frr/bgpd.conf - sudo touch /usr/local/etc/frr/ospfd.conf - sudo touch /usr/local/etc/frr/ospf6d.conf - sudo touch /usr/local/etc/frr/isisd.conf - sudo touch /usr/local/etc/frr/ripd.conf - sudo touch /usr/local/etc/frr/ripngd.conf - sudo touch /usr/local/etc/frr/pimd.conf - sudo chown -R frr:frr /usr/local/etc/frr - sudo touch /usr/local/etc/frr/vtysh.conf - sudo chown frr:frrvty /usr/local/etc/frr/vtysh.conf - sudo chmod 640 /usr/local/etc/frr/*.conf + sudo mkdir /usr/local/etc/frr + sudo touch /usr/local/etc/frr/zebra.conf + sudo touch /usr/local/etc/frr/bgpd.conf + sudo touch /usr/local/etc/frr/ospfd.conf + sudo touch /usr/local/etc/frr/ospf6d.conf + sudo touch /usr/local/etc/frr/isisd.conf + sudo touch /usr/local/etc/frr/ripd.conf + sudo touch /usr/local/etc/frr/ripngd.conf + sudo touch /usr/local/etc/frr/pimd.conf + sudo chown -R frr:frr /usr/local/etc/frr + sudo touch /usr/local/etc/frr/vtysh.conf + sudo chown frr:frrvty /usr/local/etc/frr/vtysh.conf + sudo chmod 640 /usr/local/etc/frr/*.conf ### Enable IP & IPv6 forwarding Add the following lines to the end of `/etc/sysctl.conf`: - # Routing: We need to forward packets - net.inet.ip.forwarding=1 - net.inet6.ip6.forwarding=1 + # Routing: We need to forward packets + net.inet.ip.forwarding=1 + net.inet6.ip6.forwarding=1 **Reboot** or use `sysctl` to apply the same config to the running system diff --git a/doc/Building_FRR_on_NetBSD6.md b/doc/Building_FRR_on_NetBSD6.md index 0d3f108056..03d04ce954 100644 --- a/doc/Building_FRR_on_NetBSD6.md +++ b/doc/Building_FRR_on_NetBSD6.md @@ -12,105 +12,106 @@ Install required packages ------------------------- Configure Package location: - PKG_PATH="ftp://ftp.NetBSD.org/pub/pkgsrc/packages/NetBSD/`uname -m`/`uname -r`/All" - export PKG_PATH + PKG_PATH="ftp://ftp.NetBSD.org/pub/pkgsrc/packages/NetBSD/`uname -m`/`uname -r`/All" + export PKG_PATH Add packages: - sudo pkg_add git autoconf automake libtool gmake gawk openssl pkg-config \ - json-c p5-XML-LibXML python27 py27-test - + sudo pkg_add git autoconf automake libtool gmake gawk openssl \ + pkg-config json-c p5-XML-LibXML python27 py27-test + Install SSL Root Certificates (for git https access): - sudo pkg_add mozilla-rootcerts - sudo touch /etc/openssl/openssl.cnf - sudo mozilla-rootcerts install + sudo pkg_add mozilla-rootcerts + sudo touch /etc/openssl/openssl.cnf + sudo mozilla-rootcerts install Select default Python and py.test - sudo ln -s /usr/pkg/bin/python2.7 /usr/bin/python - sudo ln -s /usr/pkg/bin/py.test-2.7 /usr/bin/py.test + sudo ln -s /usr/pkg/bin/python2.7 /usr/bin/python + sudo ln -s /usr/pkg/bin/py.test-2.7 /usr/bin/py.test Get FRR, compile it and install it (from Git) ------------------------------------------------ ### Add frr groups and user - sudo groupadd -g 92 frr - sudo groupadd -g 93 frrvty - sudo useradd -g 92 -u 92 -G frrvty -c "FRR suite" \ - -d /nonexistent -s /sbin/nologin frr - -### Download Source, configure and compile it -(You may prefer different options on configure statement. These are just an example) + sudo groupadd -g 92 frr + sudo groupadd -g 93 frrvty + sudo useradd -g 92 -u 92 -G frrvty -c "FRR suite" \ + -d /nonexistent -s /sbin/nologin frr - git clone https://github.com/freerangerouting/frr.git frr - cd frr - git checkout stable/2.0 - ./bootstrap.sh - MAKE=gmake - export LDFLAGS="-L/usr/pkg/lib -R/usr/pkg/lib" - export CPPFLAGS="-I/usr/pkg/include" - ./configure \ - --sysconfdir=/usr/pkg/etc/frr \ - --enable-exampledir=/usr/pkg/share/examples/frr \ - --enable-pkgsrcrcdir=/usr/pkg/share/examples/rc.d \ - --localstatedir=/var/run/frr \ - --enable-ospfclient=yes \ - --enable-ospfapi=yes \ - --enable-multipath=64 \ - --enable-user=frr \ - --enable-group=frr \ - --enable-vty-group=frrvty \ - --enable-configfile-mask=0640 \ - --enable-logfile-mask=0640 \ - --enable-rtadv \ - --enable-tcp-zebra \ - --enable-fpm \ - --with-pkg-git-version \ - --with-pkg-extra-version=-MyOwnFRRVersion - gmake - gmake check - sudo gmake install +### Download Source, configure and compile it +(You may prefer different options on configure statement. These are just +an example) + + git clone https://github.com/freerangerouting/frr.git frr + cd frr + git checkout stable/2.0 + ./bootstrap.sh + MAKE=gmake + export LDFLAGS="-L/usr/pkg/lib -R/usr/pkg/lib" + export CPPFLAGS="-I/usr/pkg/include" + ./configure \ + --sysconfdir=/usr/pkg/etc/frr \ + --enable-exampledir=/usr/pkg/share/examples/frr \ + --enable-pkgsrcrcdir=/usr/pkg/share/examples/rc.d \ + --localstatedir=/var/run/frr \ + --enable-ospfclient=yes \ + --enable-ospfapi=yes \ + --enable-multipath=64 \ + --enable-user=frr \ + --enable-group=frr \ + --enable-vty-group=frrvty \ + --enable-configfile-mask=0640 \ + --enable-logfile-mask=0640 \ + --enable-rtadv \ + --enable-tcp-zebra \ + --enable-fpm \ + --with-pkg-git-version \ + --with-pkg-extra-version=-MyOwnFRRVersion + gmake + gmake check + sudo gmake install ### Create empty FRR configuration files - sudo mkdir /var/log/frr - sudo mkdir /usr/pkg/etc/frr - sudo touch /usr/pkg/etc/frr/zebra.conf - sudo touch /usr/pkg/etc/frr/bgpd.conf - sudo touch /usr/pkg/etc/frr/ospfd.conf - sudo touch /usr/pkg/etc/frr/ospf6d.conf - sudo touch /usr/pkg/etc/frr/isisd.conf - sudo touch /usr/pkg/etc/frr/ripd.conf - sudo touch /usr/pkg/etc/frr/ripngd.conf - sudo touch /usr/pkg/etc/frr/pimd.conf - sudo chown -R frr:frr /usr/pkg/etc/frr - sudo touch /usr/local/etc/frr/vtysh.conf - sudo chown frr:frrvty /usr/pkg/etc/frr/*.conf - sudo chmod 640 /usr/pkg/etc/frr/*.conf + sudo mkdir /var/log/frr + sudo mkdir /usr/pkg/etc/frr + sudo touch /usr/pkg/etc/frr/zebra.conf + sudo touch /usr/pkg/etc/frr/bgpd.conf + sudo touch /usr/pkg/etc/frr/ospfd.conf + sudo touch /usr/pkg/etc/frr/ospf6d.conf + sudo touch /usr/pkg/etc/frr/isisd.conf + sudo touch /usr/pkg/etc/frr/ripd.conf + sudo touch /usr/pkg/etc/frr/ripngd.conf + sudo touch /usr/pkg/etc/frr/pimd.conf + sudo chown -R frr:frr /usr/pkg/etc/frr + sudo touch /usr/local/etc/frr/vtysh.conf + sudo chown frr:frrvty /usr/pkg/etc/frr/*.conf + sudo chmod 640 /usr/pkg/etc/frr/*.conf ### Enable IP & IPv6 forwarding Add the following lines to the end of `/etc/sysctl.conf`: - # Routing: We need to forward packets - net.inet.ip.forwarding=1 - net.inet6.ip6.forwarding=1 + # Routing: We need to forward packets + net.inet.ip.forwarding=1 + net.inet6.ip6.forwarding=1 **Reboot** or use `sysctl` to apply the same config to the running system ### Install rc.d init files - cp pkgsrc/*.sh /etc/rc.d/ - chmod 555 /etc/rc.d/*.sh + cp pkgsrc/*.sh /etc/rc.d/ + chmod 555 /etc/rc.d/*.sh ### Enable FRR processes (Enable the required processes only) - echo "zebra=YES" >> /etc/rc.conf - echo "bgpd=YES" >> /etc/rc.conf - echo "ospfd=YES" >> /etc/rc.conf - echo "ospf6d=YES" >> /etc/rc.conf - echo "isisd=YES" >> /etc/rc.conf - echo "ripngd=YES" >> /etc/rc.conf - echo "ripd=YES" >> /etc/rc.conf - echo "pimd=YES" >> /etc/rc.conf + echo "zebra=YES" >> /etc/rc.conf + echo "bgpd=YES" >> /etc/rc.conf + echo "ospfd=YES" >> /etc/rc.conf + echo "ospf6d=YES" >> /etc/rc.conf + echo "isisd=YES" >> /etc/rc.conf + echo "ripngd=YES" >> /etc/rc.conf + echo "ripd=YES" >> /etc/rc.conf + echo "pimd=YES" >> /etc/rc.conf diff --git a/doc/Building_FRR_on_NetBSD7.md b/doc/Building_FRR_on_NetBSD7.md index 22c468a6a1..d9b4b47ea6 100644 --- a/doc/Building_FRR_on_NetBSD7.md +++ b/doc/Building_FRR_on_NetBSD7.md @@ -11,99 +11,100 @@ NetBSD 7 restrictions: Install required packages ------------------------- - sudo pkgin install git autoconf automake libtool gmake gawk openssl pkg-config \ - json-c p5-XML-LibXML python27 py27-test + sudo pkgin install git autoconf automake libtool gmake gawk openssl \ + pkg-config json-c p5-XML-LibXML python27 py27-test Install SSL Root Certificates (for git https access): - sudo pkgin install mozilla-rootcerts - sudo touch /etc/openssl/openssl.cnf - sudo mozilla-rootcerts install + sudo pkgin install mozilla-rootcerts + sudo touch /etc/openssl/openssl.cnf + sudo mozilla-rootcerts install Select default Python and py.test - sudo ln -s /usr/pkg/bin/python2.7 /usr/bin/python - sudo ln -s /usr/pkg/bin/py.test-2.7 /usr/bin/py.test + sudo ln -s /usr/pkg/bin/python2.7 /usr/bin/python + sudo ln -s /usr/pkg/bin/py.test-2.7 /usr/bin/py.test Get FRR, compile it and install it (from Git) ------------------------------------------------ ### Add frr groups and user - sudo groupadd -g 92 frr - sudo groupadd -g 93 frrvty - sudo useradd -g 92 -u 92 -G frrvty -c "FRR suite" \ - -d /nonexistent -s /sbin/nologin frr + sudo groupadd -g 92 frr + sudo groupadd -g 93 frrvty + sudo useradd -g 92 -u 92 -G frrvty -c "FRR suite" \ + -d /nonexistent -s /sbin/nologin frr ### Download Source, configure and compile it -(You may prefer different options on configure statement. These are just an example) +(You may prefer different options on configure statement. These are just +an example) - git clone https://github.com/freerangerouting/frr.git frr - cd frr - git checkout stable/2.0 - ./bootstrap.sh - MAKE=gmake - export LDFLAGS="-L/usr/pkg/lib -R/usr/pkg/lib" - export CPPFLAGS="-I/usr/pkg/include" - ./configure \ - --sysconfdir=/usr/pkg/etc/frr \ - --enable-exampledir=/usr/pkg/share/examples/frr \ - --enable-pkgsrcrcdir=/usr/pkg/share/examples/rc.d \ - --localstatedir=/var/run/frr \ - --enable-ospfclient=yes \ - --enable-ospfapi=yes \ - --enable-multipath=64 \ - --enable-user=frr \ - --enable-group=frr \ - --enable-vty-group=frrvty \ - --enable-configfile-mask=0640 \ - --enable-logfile-mask=0640 \ - --enable-rtadv \ - --enable-tcp-zebra \ - --enable-fpm \ - --with-pkg-git-version \ - --with-pkg-extra-version=-MyOwnFRRVersion - gmake - gmake check - sudo gmake install + git clone https://github.com/freerangerouting/frr.git frr + cd frr + git checkout stable/2.0 + ./bootstrap.sh + MAKE=gmake + export LDFLAGS="-L/usr/pkg/lib -R/usr/pkg/lib" + export CPPFLAGS="-I/usr/pkg/include" + ./configure \ + --sysconfdir=/usr/pkg/etc/frr \ + --enable-exampledir=/usr/pkg/share/examples/frr \ + --enable-pkgsrcrcdir=/usr/pkg/share/examples/rc.d \ + --localstatedir=/var/run/frr \ + --enable-ospfclient=yes \ + --enable-ospfapi=yes \ + --enable-multipath=64 \ + --enable-user=frr \ + --enable-group=frr \ + --enable-vty-group=frrvty \ + --enable-configfile-mask=0640 \ + --enable-logfile-mask=0640 \ + --enable-rtadv \ + --enable-tcp-zebra \ + --enable-fpm \ + --with-pkg-git-version \ + --with-pkg-extra-version=-MyOwnFRRVersion + gmake + gmake check + sudo gmake install ### Create empty FRR configuration files - sudo mkdir /usr/pkg/etc/frr - sudo touch /usr/pkg/etc/frr/zebra.conf - sudo touch /usr/pkg/etc/frr/bgpd.conf - sudo touch /usr/pkg/etc/frr/ospfd.conf - sudo touch /usr/pkg/etc/frr/ospf6d.conf - sudo touch /usr/pkg/etc/frr/isisd.conf - sudo touch /usr/pkg/etc/frr/ripd.conf - sudo touch /usr/pkg/etc/frr/ripngd.conf - sudo touch /usr/pkg/etc/frr/pimd.conf - sudo chown -R frr:frr /usr/pkg/etc/frr - sudo touch /usr/local/etc/frr/vtysh.conf - sudo chown frr:frrvty /usr/pkg/etc/frr/*.conf - sudo chmod 640 /usr/pkg/etc/frr/*.conf + sudo mkdir /usr/pkg/etc/frr + sudo touch /usr/pkg/etc/frr/zebra.conf + sudo touch /usr/pkg/etc/frr/bgpd.conf + sudo touch /usr/pkg/etc/frr/ospfd.conf + sudo touch /usr/pkg/etc/frr/ospf6d.conf + sudo touch /usr/pkg/etc/frr/isisd.conf + sudo touch /usr/pkg/etc/frr/ripd.conf + sudo touch /usr/pkg/etc/frr/ripngd.conf + sudo touch /usr/pkg/etc/frr/pimd.conf + sudo chown -R frr:frr /usr/pkg/etc/frr + sudo touch /usr/local/etc/frr/vtysh.conf + sudo chown frr:frrvty /usr/pkg/etc/frr/*.conf + sudo chmod 640 /usr/pkg/etc/frr/*.conf ### Enable IP & IPv6 forwarding Add the following lines to the end of `/etc/sysctl.conf`: - # Routing: We need to forward packets - net.inet.ip.forwarding=1 - net.inet6.ip6.forwarding=1 + # Routing: We need to forward packets + net.inet.ip.forwarding=1 + net.inet6.ip6.forwarding=1 **Reboot** or use `sysctl` to apply the same config to the running system ### Install rc.d init files - cp pkgsrc/*.sh /etc/rc.d/ - chmod 555 /etc/rc.d/*.sh + cp pkgsrc/*.sh /etc/rc.d/ + chmod 555 /etc/rc.d/*.sh ### Enable FRR processes (Enable the required processes only) - echo "zebra=YES" >> /etc/rc.conf - echo "bgpd=YES" >> /etc/rc.conf - echo "ospfd=YES" >> /etc/rc.conf - echo "ospf6d=YES" >> /etc/rc.conf - echo "isisd=YES" >> /etc/rc.conf - echo "ripngd=YES" >> /etc/rc.conf - echo "ripd=YES" >> /etc/rc.conf - echo "pimd=YES" >> /etc/rc.conf + echo "zebra=YES" >> /etc/rc.conf + echo "bgpd=YES" >> /etc/rc.conf + echo "ospfd=YES" >> /etc/rc.conf + echo "ospf6d=YES" >> /etc/rc.conf + echo "isisd=YES" >> /etc/rc.conf + echo "ripngd=YES" >> /etc/rc.conf + echo "ripd=YES" >> /etc/rc.conf + echo "pimd=YES" >> /etc/rc.conf diff --git a/doc/Building_FRR_on_OmniOS.md b/doc/Building_FRR_on_OmniOS.md index 12acc92886..f158c80a75 100644 --- a/doc/Building_FRR_on_OmniOS.md +++ b/doc/Building_FRR_on_OmniOS.md @@ -4,117 +4,121 @@ Building FRR on OmniOS (OpenSolaris) from Git Source OmniOS restrictions: -------------------- -- MPLS is not supported on `OmniOS` or `Solaris`. MPLS requires a Linux Kernel - (4.5 or higher). LDP can be built, but may have limited use without MPLS +- MPLS is not supported on `OmniOS` or `Solaris`. MPLS requires a Linux + Kernel (4.5 or higher). LDP can be built, but may have limited use + without MPLS ### Enable IP & IPv6 forwarding - routeadm -e ipv4-forwarding - routeadm -e ipv6-forwarding + routeadm -e ipv4-forwarding + routeadm -e ipv6-forwarding Install required packages ------------------------- Add packages: - pkg install \ - developer/build/autoconf \ - developer/build/automake \ - developer/lexer/flex \ - developer/parser/bison \ - developer/object-file \ - developer/linker \ - developer/library/lint \ - developer/build/gnu-make \ - developer/gcc51 \ - library/idnkit \ - library/idnkit/header-idnkit \ - system/header \ - system/library/math/header-math \ - git libtool gawk pkg-config + pkg install \ + developer/build/autoconf \ + developer/build/automake \ + developer/lexer/flex \ + developer/parser/bison \ + developer/object-file \ + developer/linker \ + developer/library/lint \ + developer/build/gnu-make \ + developer/gcc51 \ + library/idnkit \ + library/idnkit/header-idnkit \ + system/header \ + system/library/math/header-math \ + git libtool gawk pkg-config Add additional Solaris packages: - pkgadd -d http://get.opencsw.org/now - /opt/csw/bin/pkgutil -U - /opt/csw/bin/pkgutil -y -i texinfo - /opt/csw/bin/pkgutil -y -i perl - /opt/csw/bin/pkgutil -y -i libjson_c_dev - /opt/csw/bin/pkgutil -y -i python27 py_pip + pkgadd -d http://get.opencsw.org/now + /opt/csw/bin/pkgutil -U + /opt/csw/bin/pkgutil -y -i texinfo + /opt/csw/bin/pkgutil -y -i perl + /opt/csw/bin/pkgutil -y -i libjson_c_dev + /opt/csw/bin/pkgutil -y -i python27 py_pip Add libjson to Solaris equivalent of ld.so.conf - crle -l /opt/csw/lib -u + crle -l /opt/csw/lib -u Add Perl packages: - cpan - cpan[1]> install XML::LibXML - cpan[2]> exit + cpan + cpan[1]> install XML::LibXML + cpan[2]> exit Add pytest: - pip install pytest + pip install pytest Select Python 2.7 as default (required for pytest) - rm -f /usr/bin/python - ln -s /opt/csw/bin/python2.7 /usr/bin/python - -Fix PATH for all users and non-interactive sessions. Edit `/etc/default/login` and add the following default PATH: + rm -f /usr/bin/python + ln -s /opt/csw/bin/python2.7 /usr/bin/python + +Fix PATH for all users and non-interactive sessions. Edit `/etc/default/login` +and add the following default PATH: + + PATH=/usr/gnu/bin:/usr/bin:/usr/sbin:/sbin:/opt/csw/bin - PATH=/usr/gnu/bin:/usr/bin:/usr/sbin:/sbin:/opt/csw/bin - Edit `~/.profile` and add the following default PATH: - PATH=/usr/gnu/bin:/usr/bin:/usr/sbin:/sbin:/opt/csw/bin + PATH=/usr/gnu/bin:/usr/bin:/usr/sbin:/sbin:/opt/csw/bin Get FRR, compile it and install it (from Git) --------------------------------------------- -**This assumes you want to build and install FRR from source and not using any packages** +**This assumes you want to build and install FRR from source and not using +any packages** ### Add frr group and user - sudo groupadd -g 93 frr - sudo groupadd -g 94 frrvty - sudo useradd -g 93 -u 93 -G frrvty -c "FRR suite" \ - -d /nonexistent -s /bin/false frr + sudo groupadd -g 93 frr + sudo groupadd -g 94 frrvty + sudo useradd -g 93 -u 93 -G frrvty -c "FRR suite" \ + -d /nonexistent -s /bin/false frr -(You may prefer different options on configure statement. These are just an example) +(You may prefer different options on configure statement. These are just +an example) - git clone https://github.com/freerangerouting/frr.git frr - cd frr - git checkout stable/2.0 - ./bootstrap.sh - export MAKE=gmake - export LDFLAGS="-L/opt/csw/lib" - export CPPFLAGS="-I/opt/csw/include" - ./configure \ - --sysconfdir=/etc/frr \ - --enable-exampledir=/usr/share/doc/frr/examples/ \ - --localstatedir=/var/run/frr \ - --sbindir=/usr/lib/frr \ - --enable-vtysh \ - --enable-watchfrr \ - --enable-ospfclient=yes \ - --enable-ospfapi=yes \ - --enable-multipath=64 \ - --enable-user=frr \ - --enable-group=frr \ - --enable-vty-group=frrvty \ - --enable-configfile-mask=0640 \ - --enable-logfile-mask=0640 \ - --enable-rtadv \ - --enable-tcp-zebra \ - --enable-fpm \ - --with-pkg-git-version \ - --with-pkg-extra-version=-MyOwnFRRVersion - gmake - gmake check - sudo gmake install + git clone https://github.com/freerangerouting/frr.git frr + cd frr + git checkout stable/2.0 + ./bootstrap.sh + export MAKE=gmake + export LDFLAGS="-L/opt/csw/lib" + export CPPFLAGS="-I/opt/csw/include" + ./configure \ + --sysconfdir=/etc/frr \ + --enable-exampledir=/usr/share/doc/frr/examples/ \ + --localstatedir=/var/run/frr \ + --sbindir=/usr/lib/frr \ + --enable-vtysh \ + --enable-watchfrr \ + --enable-ospfclient=yes \ + --enable-ospfapi=yes \ + --enable-multipath=64 \ + --enable-user=frr \ + --enable-group=frr \ + --enable-vty-group=frrvty \ + --enable-configfile-mask=0640 \ + --enable-logfile-mask=0640 \ + --enable-rtadv \ + --enable-tcp-zebra \ + --enable-fpm \ + --with-pkg-git-version \ + --with-pkg-extra-version=-MyOwnFRRVersion + gmake + gmake check + sudo gmake install ### Enable IP & IPv6 forwarding - routeadm -e ipv4-forwarding - routeadm -e ipv6-forwarding + routeadm -e ipv4-forwarding + routeadm -e ipv6-forwarding diff --git a/doc/Building_FRR_on_OpenBSD6.md b/doc/Building_FRR_on_OpenBSD6.md index 3f390d5eb7..9e13d5ce45 100644 --- a/doc/Building_FRR_on_OpenBSD6.md +++ b/doc/Building_FRR_on_OpenBSD6.md @@ -12,80 +12,82 @@ Install required packages Configure PKG_PATH - export PKG_PATH=http://ftp5.usa.openbsd.org/pub/OpenBSD/$(uname -r)/packages/$(machine -a)/ + export PKG_PATH=http://ftp5.usa.openbsd.org/pub/OpenBSD/$(uname -r)/packages/$(machine -a)/ Add packages: - pkg_add git autoconf-2.69p2 automake-1.15p0 libtool - pkg_add gmake gawk dejagnu openssl json-c p5-XML-LibXML py-test + pkg_add git autoconf-2.69p2 automake-1.15p0 libtool + pkg_add gmake gawk dejagnu openssl json-c p5-XML-LibXML py-test Select Python2.7 as default (required for pytest) - ln -s /usr/local/bin/python2.7 /usr/local/bin/python - + ln -s /usr/local/bin/python2.7 /usr/local/bin/python + Get FRR, compile it and install it (from Git) --------------------------------------------- -**This assumes you want to build and install FRR from source and not using any packages** +**This assumes you want to build and install FRR from source and not using +any packages** ### Add frr group and user - groupadd -g 525 _frr - groupadd -g 526 _frrvty - useradd -g 525 -u 525 -c "FRR suite" -G _frrvty \ - -d /nonexistent -s /sbin/nologin _frr + groupadd -g 525 _frr + groupadd -g 526 _frrvty + useradd -g 525 -u 525 -c "FRR suite" -G _frrvty \ + -d /nonexistent -s /sbin/nologin _frr ### Download Source, configure and compile it -(You may prefer different options on configure statement. These are just an example) +(You may prefer different options on configure statement. These are just +an example) - git clone https://github.com/freerangerouting/frr.git frr - cd frr - git checkout stable/2.0 - ./bootstrap.sh - export LDFLAGS="-L/usr/local/lib" - export CPPFLAGS="-I/usr/local/include" - ./configure \ - --sysconfdir=/etc/frr \ - --localstatedir=/var/frr \ - --enable-pimd \ - --enable-ospfclient=yes \ - --enable-ospfapi=yes \ - --enable-multipath=64 \ - --enable-user=_frr \ - --enable-group=_frr \ - --enable-vty-group=_frrvty \ - --enable-configfile-mask=0640 \ - --enable-logfile-mask=0640 \ - --enable-rtadv \ - --enable-tcp-zebra \ - --enable-fpm \ - --enable-ldpd \ - --with-pkg-git-version \ - --with-pkg-extra-version=-MyOwnFRRVersion - gmake - gmake check - sudo gmake install + git clone https://github.com/freerangerouting/frr.git frr + cd frr + git checkout stable/2.0 + ./bootstrap.sh + export LDFLAGS="-L/usr/local/lib" + export CPPFLAGS="-I/usr/local/include" + ./configure \ + --sysconfdir=/etc/frr \ + --localstatedir=/var/frr \ + --enable-pimd \ + --enable-ospfclient=yes \ + --enable-ospfapi=yes \ + --enable-multipath=64 \ + --enable-user=_frr \ + --enable-group=_frr \ + --enable-vty-group=_frrvty \ + --enable-configfile-mask=0640 \ + --enable-logfile-mask=0640 \ + --enable-rtadv \ + --enable-tcp-zebra \ + --enable-fpm \ + --enable-ldpd \ + --with-pkg-git-version \ + --with-pkg-extra-version=-MyOwnFRRVersion + gmake + gmake check + sudo gmake install ### Create empty FRR configuration files - sudo mkdir /var/frr - sudo chown _frr:_frr /var/frr - sudo chmod 755 /var/frr - sudo mkdir /etc/frr - sudo touch /etc/frr/zebra.conf - sudo touch /etc/frr/bgpd.conf - sudo touch /etc/frr/ospfd.conf - sudo touch /etc/frr/ospf6d.conf - sudo touch /etc/frr/isisd.conf - sudo touch /etc/frr/ripd.conf - sudo touch /etc/frr/ripngd.conf - sudo touch /etc/frr/pimd.conf - sudo touch /etc/frr/ldpd.conf - sudo chown -R _frr:_frr /etc/frr - sudo touch /etc/frr/vtysh.conf - sudo chown -R _frr:_frrvty /etc/frr/vtysh.conf - sudo chmod 750 /etc/frr - sudo chmod 640 /etc/frr/*.conf + sudo mkdir /var/frr + sudo chown _frr:_frr /var/frr + sudo chmod 755 /var/frr + sudo mkdir /etc/frr + sudo touch /etc/frr/zebra.conf + sudo touch /etc/frr/bgpd.conf + sudo touch /etc/frr/ospfd.conf + sudo touch /etc/frr/ospf6d.conf + sudo touch /etc/frr/isisd.conf + sudo touch /etc/frr/ripd.conf + sudo touch /etc/frr/ripngd.conf + sudo touch /etc/frr/pimd.conf + sudo touch /etc/frr/ldpd.conf + sudo chown -R _frr:_frr /etc/frr + sudo touch /etc/frr/vtysh.conf + sudo chown -R _frr:_frrvty /etc/frr/vtysh.conf + sudo chmod 750 /etc/frr + sudo chmod 640 /etc/frr/*.conf ### Enable IP & IPv6 forwarding @@ -98,29 +100,30 @@ Add the following lines to the end of `/etc/rc.conf`: **Reboot** to apply the config to the system ### Install rc.d init files -(create them in /etc/rc.d - no example are included at this time with FRR source) +(create them in /etc/rc.d - no example are included at this time with +FRR source) Example (for zebra - store as `/etc/rc.d/frr_zebra.sh`) - #!/bin/sh - # - # $OpenBSD: frr_zebra.rc,v 1.1 2013/04/18 20:29:08 sthen Exp $ - - daemon="/usr/local/sbin/zebra -d" - - . /etc/rc.d/rc.subr - - rc_cmd $1 + #!/bin/sh + # + # $OpenBSD: frr_zebra.rc,v 1.1 2013/04/18 20:29:08 sthen Exp $ + + daemon="/usr/local/sbin/zebra -d" + + . /etc/rc.d/rc.subr + + rc_cmd $1 ### Enable FRR processes (Enable the required processes only) - echo "frr_zebra=YES" >> /etc/rc.conf - echo "frr_bgpd=YES" >> /etc/rc.conf - echo "frr_ospfd=YES" >> /etc/rc.conf - echo "frr_ospf6d=YES" >> /etc/rc.conf - echo "frr_isisd=YES" >> /etc/rc.conf - echo "frr_ripngd=YES" >> /etc/rc.conf - echo "frr_ripd=YES" >> /etc/rc.conf - echo "frr_pimd=YES" >> /etc/rc.conf - echo "frr_ldpd=YES" >> /etc/rc.conf + echo "frr_zebra=YES" >> /etc/rc.conf + echo "frr_bgpd=YES" >> /etc/rc.conf + echo "frr_ospfd=YES" >> /etc/rc.conf + echo "frr_ospf6d=YES" >> /etc/rc.conf + echo "frr_isisd=YES" >> /etc/rc.conf + echo "frr_ripngd=YES" >> /etc/rc.conf + echo "frr_ripd=YES" >> /etc/rc.conf + echo "frr_pimd=YES" >> /etc/rc.conf + echo "frr_ldpd=YES" >> /etc/rc.conf diff --git a/doc/Building_FRR_on_Ubuntu1204.md b/doc/Building_FRR_on_Ubuntu1204.md index 98ee2b831a..60b714d4d2 100644 --- a/doc/Building_FRR_on_Ubuntu1204.md +++ b/doc/Building_FRR_on_Ubuntu1204.md @@ -8,121 +8,125 @@ Building FRR on Ubuntu 12.04LTS from Git Source Install required packages ------------------------- - + Add packages: - apt-get install git autoconf automake libtool make gawk libreadline-dev texinfo \ - libpam0g-dev dejagnu libjson0 pkg-config libpam0g-dev libjson0-dev flex \ - python-pytest + apt-get install git autoconf automake libtool make gawk libreadline-dev \ + texinfo libpam0g-dev dejagnu libjson0 pkg-config libpam0g-dev \ + libjson0-dev flex python-pytest -Install newer bison from 14.04 package source (Ubuntu 12.04 package source is too old) +Install newer bison from 14.04 package source (Ubuntu 12.04 package source +is too old) - mkdir builddir - cd builddir - wget http://archive.ubuntu.com/ubuntu/pool/main/b/bison/bison_3.0.2.dfsg-2.dsc - wget http://archive.ubuntu.com/ubuntu/pool/main/b/bison/bison_3.0.2.dfsg.orig.tar.bz2 - wget http://archive.ubuntu.com/ubuntu/pool/main/b/bison/bison_3.0.2.dfsg-2.debian.tar.gz - tar -jxvf bison_3.0.2.dfsg.orig.tar.bz2 - cd bison-3.0.2.dfsg/ - tar xzf ../bison_3.0.2.dfsg-2.debian.tar.gz - sudo apt-get build-dep bison - debuild -b -uc -us - cd .. - sudo dpkg -i ./libbison-dev_3.0.2.dfsg-2_amd64.deb ./bison_3.0.2.dfsg-2_amd64.deb - cd .. - rm -rf builddir + mkdir builddir + cd builddir + wget http://archive.ubuntu.com/ubuntu/pool/main/b/bison/bison_3.0.2.dfsg-2.dsc + wget http://archive.ubuntu.com/ubuntu/pool/main/b/bison/bison_3.0.2.dfsg.orig.tar.bz2 + wget http://archive.ubuntu.com/ubuntu/pool/main/b/bison/bison_3.0.2.dfsg-2.debian.tar.gz + tar -jxvf bison_3.0.2.dfsg.orig.tar.bz2 + cd bison-3.0.2.dfsg/ + tar xzf ../bison_3.0.2.dfsg-2.debian.tar.gz + sudo apt-get build-dep bison + debuild -b -uc -us + cd .. + sudo dpkg -i ./libbison-dev_3.0.2.dfsg-2_amd64.deb ./bison_3.0.2.dfsg-2_amd64.deb + cd .. + rm -rf builddir Install newer version of autoconf and automake: - wget http://ftp.gnu.org/gnu/autoconf/autoconf-2.69.tar.gz - tar xvf autoconf-2.69.tar.gz - cd autoconf-2.69 - ./configure --prefix=/usr - make - sudo make install - cd .. - - wget http://ftp.gnu.org/gnu/automake/automake-1.15.tar.gz - tar xvf automake-1.15.tar.gz - cd automake-1.15 - ./configure --prefix=/usr - make - sudo make install - cd .. - + wget http://ftp.gnu.org/gnu/autoconf/autoconf-2.69.tar.gz + tar xvf autoconf-2.69.tar.gz + cd autoconf-2.69 + ./configure --prefix=/usr + make + sudo make install + cd .. + + wget http://ftp.gnu.org/gnu/automake/automake-1.15.tar.gz + tar xvf automake-1.15.tar.gz + cd automake-1.15 + ./configure --prefix=/usr + make + sudo make install + cd .. + Get FRR, compile it and install it (from Git) --------------------------------------------- -**This assumes you want to build and install FRR from source and not using any packages** +**This assumes you want to build and install FRR from source and not using +any packages** ### Add frr groups and user - sudo groupadd -g 92 frr - sudo groupadd -r -g 85 frrvty - sudo adduser --system --ingroup frr --groups frrvty --home /var/run/frr/ \ + sudo groupadd -g 92 frr + sudo groupadd -r -g 85 frrvty + sudo adduser --system --ingroup frr --groups frrvty --home /var/run/frr/ \ --gecos "FRR suite" --shell /sbin/nologin frr ### Download Source, configure and compile it -(You may prefer different options on configure statement. These are just an example.) +(You may prefer different options on configure statement. These are just +an example.) - git clone https://github.com/freerangerouting/frr.git frr - cd frr - git checkout stable/2.0 - ./bootstrap.sh - ./configure \ - --enable-exampledir=/usr/share/doc/frr/examples/ \ - --localstatedir=/var/run/frr \ - --sbindir=/usr/lib/frr \ - --sysconfdir=/etc/frr \ - --enable-pimd \ - --enable-watchfrr \ - --enable-ospfclient=yes \ - --enable-ospfapi=yes \ - --enable-multipath=64 \ - --enable-user=frr \ - --enable-group=frr \ - --enable-vty-group=frrvty \ - --enable-configfile-mask=0640 \ - --enable-logfile-mask=0640 \ - --enable-rtadv \ - --enable-tcp-zebra \ - --enable-fpm \ - --enable-ldpd \ - --with-pkg-git-version \ - --with-pkg-extra-version=-MyOwnFRRVersion - make - make check - sudo make install + git clone https://github.com/freerangerouting/frr.git frr + cd frr + git checkout stable/2.0 + ./bootstrap.sh + ./configure \ + --enable-exampledir=/usr/share/doc/frr/examples/ \ + --localstatedir=/var/run/frr \ + --sbindir=/usr/lib/frr \ + --sysconfdir=/etc/frr \ + --enable-pimd \ + --enable-watchfrr \ + --enable-ospfclient=yes \ + --enable-ospfapi=yes \ + --enable-multipath=64 \ + --enable-user=frr \ + --enable-group=frr \ + --enable-vty-group=frrvty \ + --enable-configfile-mask=0640 \ + --enable-logfile-mask=0640 \ + --enable-rtadv \ + --enable-tcp-zebra \ + --enable-fpm \ + --enable-ldpd \ + --with-pkg-git-version \ + --with-pkg-extra-version=-MyOwnFRRVersion + make + make check + sudo make install ### Create empty FRR configuration files - sudo mkdir /var/log/frr - sudo chown frr:fee /var/log/frr - sudo mkdir /etc/frr - sudo touch /etc/frr/etc/zebra.conf - sudo touch /etc/frr/etc/bgpd.conf - sudo touch /etc/frr/etc/ospfd.conf - sudo touch /etc/frr/etc/ospf6d.conf - sudo touch /etc/frr/etc/isisd.conf - sudo touch /etc/frr/etc/ripd.conf - sudo touch /etc/frr/etc/ripngd.conf - sudo touch /etc/frr/etc/pimd.conf - sudo touch /etc/frr/etc/ldpd.conf - sudo chown frr:frr /etc/frr/ - sudo touch /etc/frr/etc/vtysh.conf - sudo chown frr:frrvty /etc/frr/etc/vtysh.conf - sudo chmod 640 /etc/frr/*.conf + sudo mkdir /var/log/frr + sudo chown frr:fee /var/log/frr + sudo mkdir /etc/frr + sudo touch /etc/frr/etc/zebra.conf + sudo touch /etc/frr/etc/bgpd.conf + sudo touch /etc/frr/etc/ospfd.conf + sudo touch /etc/frr/etc/ospf6d.conf + sudo touch /etc/frr/etc/isisd.conf + sudo touch /etc/frr/etc/ripd.conf + sudo touch /etc/frr/etc/ripngd.conf + sudo touch /etc/frr/etc/pimd.conf + sudo touch /etc/frr/etc/ldpd.conf + sudo chown frr:frr /etc/frr/ + sudo touch /etc/frr/etc/vtysh.conf + sudo chown frr:frrvty /etc/frr/etc/vtysh.conf + sudo chmod 640 /etc/frr/*.conf ### Enable IP & IPv6 forwarding -Edit `/etc/sysctl.conf` and uncomment the following values (ignore the other settings) +Edit `/etc/sysctl.conf` and uncomment the following values (ignore the +other settings) - # Uncomment the next line to enable packet forwarding for IPv4 - net.ipv4.ip_forward=1 + # Uncomment the next line to enable packet forwarding for IPv4 + net.ipv4.ip_forward=1 - # Uncomment the next line to enable packet forwarding for IPv6 - # Enabling this option disables Stateless Address Autoconfiguration - # based on Router Advertisements for this host - net.ipv6.conf.all.forwarding=1 + # Uncomment the next line to enable packet forwarding for IPv6 + # Enabling this option disables Stateless Address Autoconfiguration + # based on Router Advertisements for this host + net.ipv6.conf.all.forwarding=1 **Reboot** or use `sysctl` to apply the same config to the running system diff --git a/doc/Building_FRR_on_Ubuntu1404.md b/doc/Building_FRR_on_Ubuntu1404.md index 3198428596..ac0a45acdf 100644 --- a/doc/Building_FRR_on_Ubuntu1404.md +++ b/doc/Building_FRR_on_Ubuntu1404.md @@ -8,81 +8,87 @@ Building FRR on Ubuntu 14.04LTS from Git Source Install required packages ------------------------- - + Add packages: - apt-get install git autoconf automake libtool make gawk libreadline-dev texinfo \ - dejagnu pkg-config libpam0g-dev libjson-c-dev bison flex python-pytest - + apt-get install git autoconf automake libtool make gawk libreadline-dev \ + texinfo dejagnu pkg-config libpam0g-dev libjson-c-dev bison flex \ + python-pytest + Get FRR, compile it and install it (from Git) --------------------------------------------- +**This assumes you want to build and install FRR from source and not using +any packages** + ### Add frr groups and user - sudo groupadd -g 92 frr - sudo groupadd -r -g 85 frrvty - sudo adduser --system --ingroup frr --groups frrvty --home /var/run/frr/ \ + sudo groupadd -g 92 frr + sudo groupadd -r -g 85 frrvty + sudo adduser --system --ingroup frr --groups frrvty --home /var/run/frr/ \ --gecos "FRR suite" --shell /sbin/nologin frr ### Download Source, configure and compile it -(You may prefer different options on configure statement. These are just an example.) +(You may prefer different options on configure statement. These are just +an example.) - git clone https://github.com/freerangerouting/frr.git frr - cd frr - git checkout stable/2.0 - ./bootstrap.sh - ./configure \ - --enable-exampledir=/usr/share/doc/frr/examples/ \ - --localstatedir=/var/run/frr \ - --sbindir=/usr/lib/frr \ - --sysconfdir=/etc/frr \ - --enable-pimd \ - --enable-watchfrr \ - --enable-ospfclient=yes \ - --enable-ospfapi=yes \ - --enable-multipath=64 \ - --enable-user=frr \ - --enable-group=frr \ - --enable-vty-group=frrvty \ - --enable-configfile-mask=0640 \ - --enable-logfile-mask=0640 \ - --enable-rtadv \ - --enable-tcp-zebra \ - --enable-fpm \ - --with-pkg-git-version \ - --with-pkg-extra-version=-MyOwnFRRVersion - make - make check - sudo make install + git clone https://github.com/freerangerouting/frr.git frr + cd frr + git checkout stable/2.0 + ./bootstrap.sh + ./configure \ + --enable-exampledir=/usr/share/doc/frr/examples/ \ + --localstatedir=/var/run/frr \ + --sbindir=/usr/lib/frr \ + --sysconfdir=/etc/frr \ + --enable-pimd \ + --enable-watchfrr \ + --enable-ospfclient=yes \ + --enable-ospfapi=yes \ + --enable-multipath=64 \ + --enable-user=frr \ + --enable-group=frr \ + --enable-vty-group=frrvty \ + --enable-configfile-mask=0640 \ + --enable-logfile-mask=0640 \ + --enable-rtadv \ + --enable-tcp-zebra \ + --enable-fpm \ + --with-pkg-git-version \ + --with-pkg-extra-version=-MyOwnFRRVersion + make + make check + sudo make install ### Create empty FRR configuration files - sudo mkdir /var/log/frr - sudo chown frr:fee /var/log/frr - sudo mkdir /etc/frr - sudo touch /etc/frr/etc/zebra.conf - sudo touch /etc/frr/etc/bgpd.conf - sudo touch /etc/frr/etc/ospfd.conf - sudo touch /etc/frr/etc/ospf6d.conf - sudo touch /etc/frr/etc/isisd.conf - sudo touch /etc/frr/etc/ripd.conf - sudo touch /etc/frr/etc/ripngd.conf - sudo touch /etc/frr/etc/pimd.conf - sudo chown frr:frr /etc/frr/ - sudo touch /etc/frr/etc/vtysh.conf - sudo chown frr:frrvty /etc/frr/etc/vtysh.conf - sudo chmod 640 /etc/frr/*.conf + sudo mkdir /var/log/frr + sudo chown frr:fee /var/log/frr + sudo mkdir /etc/frr + sudo touch /etc/frr/etc/zebra.conf + sudo touch /etc/frr/etc/bgpd.conf + sudo touch /etc/frr/etc/ospfd.conf + sudo touch /etc/frr/etc/ospf6d.conf + sudo touch /etc/frr/etc/isisd.conf + sudo touch /etc/frr/etc/ripd.conf + sudo touch /etc/frr/etc/ripngd.conf + sudo touch /etc/frr/etc/pimd.conf + sudo chown frr:frr /etc/frr/ + sudo touch /etc/frr/etc/vtysh.conf + sudo chown frr:frrvty /etc/frr/etc/vtysh.conf + sudo chmod 640 /etc/frr/*.conf ### Enable IP & IPv6 forwarding -Edit `/etc/sysctl.conf` and uncomment the following values (ignore the other settings) +Edit `/etc/sysctl.conf` and uncomment the following values (ignore the +other settings) - # Uncomment the next line to enable packet forwarding for IPv4 - net.ipv4.ip_forward=1 + # Uncomment the next line to enable packet forwarding for IPv4 + net.ipv4.ip_forward=1 - # Uncomment the next line to enable packet forwarding for IPv6 - # Enabling this option disables Stateless Address Autoconfiguration - # based on Router Advertisements for this host - net.ipv6.conf.all.forwarding=1 + # Uncomment the next line to enable packet forwarding for IPv6 + # Enabling this option disables Stateless Address Autoconfiguration + # based on Router Advertisements for this host + net.ipv6.conf.all.forwarding=1 **Reboot** or use `sysctl` to apply the same config to the running system diff --git a/doc/Building_FRR_on_Ubuntu1604.md b/doc/Building_FRR_on_Ubuntu1604.md index 03f4d6d9e4..d1e1a377d0 100644 --- a/doc/Building_FRR_on_Ubuntu1604.md +++ b/doc/Building_FRR_on_Ubuntu1604.md @@ -1,111 +1,116 @@ -Building FRR on Ubuntu 12.04LTS from Git Source +Building FRR on Ubuntu 16.04LTS from Git Source =============================================== -- MPLS is not supported on `Ubuntu 12.04` with default kernel. MPLS requires +- MPLS is not supported on `Ubuntu 16.04` with default kernel. MPLS requires Linux Kernel 4.5 or higher (LDP can be built, but may have limited use without MPLS) - For an updated Ubuntu Kernel, see http://kernel.ubuntu.com/~kernel-ppa/mainline/ + For an updated Ubuntu Kernel, see + http://kernel.ubuntu.com/~kernel-ppa/mainline/ Install required packages ------------------------- - + Add packages: - apt-get install git autoconf automake libtool make gawk libreadline-dev texinfo \ - dejagnu pkg-config libpam0g-dev libjson-c-dev bison flex python-pytest - + apt-get install git autoconf automake libtool make gawk libreadline-dev \ + texinfo dejagnu pkg-config libpam0g-dev libjson-c-dev bison flex \ + python-pytest + Get FRR, compile it and install it (from Git) --------------------------------------------- -**This assumes you want to build and install FRR from source and not using any packages** +**This assumes you want to build and install FRR from source and not using +any packages** ### Add frr groups and user - sudo groupadd -g 92 frr - sudo groupadd -r -g 85 frrvty - sudo adduser --system --ingroup frr --groups frrvty --home /var/run/frr/ \ + sudo groupadd -g 92 frr + sudo groupadd -r -g 85 frrvty + sudo adduser --system --ingroup frr --groups frrvty --home /var/run/frr/ \ --gecos "FRR suite" --shell /sbin/nologin frr ### Download Source, configure and compile it -(You may prefer different options on configure statement. These are just an example.) +(You may prefer different options on configure statement. These are just +an example.) - git clone https://github.com/freerangerouting/frr.git frr - cd frr - git checkout stable/2.0 - ./bootstrap.sh - ./configure \ - --enable-exampledir=/usr/share/doc/frr/examples/ \ - --localstatedir=/var/run/frr \ - --sbindir=/usr/lib/frr \ - --sysconfdir=/etc/frr \ - --enable-pimd \ - --enable-watchfrr \ - --enable-ospfclient=yes \ - --enable-ospfapi=yes \ - --enable-multipath=64 \ - --enable-user=frr \ - --enable-group=frr \ - --enable-vty-group=frrvty \ - --enable-configfile-mask=0640 \ - --enable-logfile-mask=0640 \ - --enable-rtadv \ - --enable-tcp-zebra \ - --enable-fpm \ - --enable-ldpd \ - --with-pkg-git-version \ - --with-pkg-extra-version=-MyOwnFRRVersion - make - make check - sudo make install + git clone https://github.com/freerangerouting/frr.git frr + cd frr + git checkout stable/2.0 + ./bootstrap.sh + ./configure \ + --enable-exampledir=/usr/share/doc/frr/examples/ \ + --localstatedir=/var/run/frr \ + --sbindir=/usr/lib/frr \ + --sysconfdir=/etc/frr \ + --enable-pimd \ + --enable-watchfrr \ + --enable-ospfclient=yes \ + --enable-ospfapi=yes \ + --enable-multipath=64 \ + --enable-user=frr \ + --enable-group=frr \ + --enable-vty-group=frrvty \ + --enable-configfile-mask=0640 \ + --enable-logfile-mask=0640 \ + --enable-rtadv \ + --enable-tcp-zebra \ + --enable-fpm \ + --enable-ldpd \ + --with-pkg-git-version \ + --with-pkg-extra-version=-MyOwnFRRVersion + make + make check + sudo make install ### Create empty FRR configuration files - sudo mkdir /var/log/frr - sudo chown frr:fee /var/log/frr - sudo mkdir /etc/frr - sudo touch /etc/frr/etc/zebra.conf - sudo touch /etc/frr/etc/bgpd.conf - sudo touch /etc/frr/etc/ospfd.conf - sudo touch /etc/frr/etc/ospf6d.conf - sudo touch /etc/frr/etc/isisd.conf - sudo touch /etc/frr/etc/ripd.conf - sudo touch /etc/frr/etc/ripngd.conf - sudo touch /etc/frr/etc/pimd.conf - sudo touch /etc/frr/etc/ldpd.conf - sudo chown frr:frr /etc/frr/ - sudo touch /etc/frr/etc/vtysh.conf - sudo chown frr:frrvty /etc/frr/etc/vtysh.conf - sudo chmod 640 /etc/frr/*.conf + sudo mkdir /var/log/frr + sudo chown frr:fee /var/log/frr + sudo mkdir /etc/frr + sudo touch /etc/frr/etc/zebra.conf + sudo touch /etc/frr/etc/bgpd.conf + sudo touch /etc/frr/etc/ospfd.conf + sudo touch /etc/frr/etc/ospf6d.conf + sudo touch /etc/frr/etc/isisd.conf + sudo touch /etc/frr/etc/ripd.conf + sudo touch /etc/frr/etc/ripngd.conf + sudo touch /etc/frr/etc/pimd.conf + sudo touch /etc/frr/etc/ldpd.conf + sudo chown frr:frr /etc/frr/ + sudo touch /etc/frr/etc/vtysh.conf + sudo chown frr:frrvty /etc/frr/etc/vtysh.conf + sudo chmod 640 /etc/frr/*.conf ### Enable IP & IPv6 forwarding -Edit `/etc/sysctl.conf` and uncomment the following values (ignore the other settings) +Edit `/etc/sysctl.conf` and uncomment the following values (ignore the +other settings) - # Uncomment the next line to enable packet forwarding for IPv4 - net.ipv4.ip_forward=1 + # Uncomment the next line to enable packet forwarding for IPv4 + net.ipv4.ip_forward=1 - # Uncomment the next line to enable packet forwarding for IPv6 - # Enabling this option disables Stateless Address Autoconfiguration - # based on Router Advertisements for this host - net.ipv6.conf.all.forwarding=1 + # Uncomment the next line to enable packet forwarding for IPv6 + # Enabling this option disables Stateless Address Autoconfiguration + # based on Router Advertisements for this host + net.ipv6.conf.all.forwarding=1 ### Enable MPLS Forwarding (with Linux Kernel >= 4.5) -Edit `/etc/sysctl.conf` and the following lines. Make sure to add a line equal to -`net.mpls.conf.eth0.input` or each interface used with MPLS +Edit `/etc/sysctl.conf` and the following lines. Make sure to add a line +equal to `net.mpls.conf.eth0.input` or each interface used with MPLS - # Enable MPLS Label processing on all interfaces - net.mpls.conf.eth0.input=1 - net.mpls.conf.eth1.input=1 - net.mpls.conf.eth2.input=1 - net.mpls.platform_labels=100000 + # Enable MPLS Label processing on all interfaces + net.mpls.conf.eth0.input=1 + net.mpls.conf.eth1.input=1 + net.mpls.conf.eth2.input=1 + net.mpls.platform_labels=100000 ### Add MPLS kernel modules Add the following lines to `/etc/modules-load.d/modules.conf`: - # Load MPLS Kernel Modules - mpls-router - mpls-iptunnel + # Load MPLS Kernel Modules + mpls-router + mpls-iptunnel **Reboot** or use `sysctl` to apply the same config to the running system From 783c4c8fa36f0e9ca12a5303e41487db5afb87cc Mon Sep 17 00:00:00 2001 From: Martin Winter Date: Fri, 17 Feb 2017 00:52:07 +0700 Subject: [PATCH 23/27] doc: Fix pytest installation instructions on Ubuntu 12.04 Ubuntu 12.04 doesn't have a pytest package - needs to be installed with pip Signed-off-by: Martin Winter --- doc/Building_FRR_on_Ubuntu1204.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/doc/Building_FRR_on_Ubuntu1204.md b/doc/Building_FRR_on_Ubuntu1204.md index 60b714d4d2..3312a2c9c8 100644 --- a/doc/Building_FRR_on_Ubuntu1204.md +++ b/doc/Building_FRR_on_Ubuntu1204.md @@ -13,7 +13,7 @@ Add packages: apt-get install git autoconf automake libtool make gawk libreadline-dev \ texinfo libpam0g-dev dejagnu libjson0 pkg-config libpam0g-dev \ - libjson0-dev flex python-pytest + libjson0-dev flex python-pip Install newer bison from 14.04 package source (Ubuntu 12.04 package source is too old) @@ -51,6 +51,10 @@ Install newer version of autoconf and automake: sudo make install cd .. +Install pytest: + + pip install pytest + Get FRR, compile it and install it (from Git) --------------------------------------------- From 402978244166ffcfb5c6fa38b7574c6ff6865a7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=9Fingen?= Date: Tue, 21 Feb 2017 12:27:44 +0100 Subject: [PATCH 24/27] Add missing DESC_ENTRY to lib/log.c --- lib/log.c | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/log.c b/lib/log.c index 6a3ce07799..a6153c2a2d 100644 --- a/lib/log.c +++ b/lib/log.c @@ -983,6 +983,7 @@ static const struct zebra_desc_table command_types[] = { DESC_ENTRY (ZEBRA_INTERFACE_ENABLE_RADV), DESC_ENTRY (ZEBRA_INTERFACE_DISABLE_RADV), DESC_ENTRY (ZEBRA_IPV4_NEXTHOP_LOOKUP_MRIB), + DESC_ENTRY (ZEBRA_INTERFACE_LINK_PARAMS), DESC_ENTRY (ZEBRA_MPLS_LABELS_ADD), DESC_ENTRY (ZEBRA_MPLS_LABELS_DELETE), DESC_ENTRY (ZEBRA_IPV4_NEXTHOP_ADD), From 5753eb9197c75609205659ad64e0ed9247810cb2 Mon Sep 17 00:00:00 2001 From: Martin Winter Date: Thu, 23 Feb 2017 19:47:59 +0700 Subject: [PATCH 25/27] release: FRR 2.0-rc2 Signed-off-by: Martin Winter --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 4390539918..7e546d7643 100755 --- a/configure.ac +++ b/configure.ac @@ -7,7 +7,7 @@ ## AC_PREREQ(2.60) -AC_INIT(frr, 2.0-rc1, [https://github.com/freerangerouting/frr/issues]) +AC_INIT(frr, 2.0-rc2, [https://github.com/freerangerouting/frr/issues]) PACKAGE_URL="https://freerangerouting.org/" PACKAGE_FULLNAME="FreeRangeRouting" AC_SUBST(PACKAGE_FULLNAME) From b79d6f95a3e716708b8010ddd03a3fa4272792a6 Mon Sep 17 00:00:00 2001 From: Christian Franke Date: Thu, 23 Feb 2017 14:27:00 +0100 Subject: [PATCH 26/27] bgpd: fix bgp_info_addpath_{rx,tx}_str if addpath info is not present The buffer needs to be set to length 0 if nothing is written into it, otherwise bgpd will log uninitialized memory, disclosing information and possibly leading to a crash. Signed-off-by: Christian Franke --- bgpd/bgp_route.c | 2 ++ bgpd/bgp_updgrp_packet.c | 2 ++ 2 files changed, 4 insertions(+) diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index 3e5251a7ff..353ecd6934 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -2281,6 +2281,8 @@ bgp_info_addpath_rx_str(u_int32_t addpath_id, char *buf) { if (addpath_id) sprintf(buf, " with addpath ID %d", addpath_id); + else + buf[0] = '\0'; } diff --git a/bgpd/bgp_updgrp_packet.c b/bgpd/bgp_updgrp_packet.c index ce2e0dbca0..0dcc8fb222 100644 --- a/bgpd/bgp_updgrp_packet.c +++ b/bgpd/bgp_updgrp_packet.c @@ -619,6 +619,8 @@ bgp_info_addpath_tx_str (int addpath_encode, u_int32_t addpath_tx_id, { if (addpath_encode) sprintf(buf, " with addpath ID %d", addpath_tx_id); + else + buf[0] = '\0'; } /* Make BGP update packet. */ From 5f3b76145ee10eaf77f64a73a90be4074ea75ccf Mon Sep 17 00:00:00 2001 From: Lou Berger Date: Thu, 23 Feb 2017 17:48:47 -0500 Subject: [PATCH 27/27] bgpd: Fix issue #218 Wrong offset was used when using global V6 address in place of v6 LL. (Introduced in earlier fix of broken RD advertisement.) Tested by @dslice in master. Signed-off-by: Lou Berger --- bgpd/bgp_updgrp_packet.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bgpd/bgp_updgrp_packet.c b/bgpd/bgp_updgrp_packet.c index 0dcc8fb222..fe60fc3fb8 100644 --- a/bgpd/bgp_updgrp_packet.c +++ b/bgpd/bgp_updgrp_packet.c @@ -546,7 +546,7 @@ bpacket_reformat_for_peer (struct bpacket *pkt, struct peer_af *paf) } if (gnh_modified) - stream_put_in6_addr_at (s, vec->offset + 1 + (nhlen-IPV6_MAX_BYTELEN), mod_v6nhg); + stream_put_in6_addr_at (s, vec->offset + 1, mod_v6nhg); if (lnh_modified) stream_put_in6_addr_at (s, vec->offset + 1 + (nhlen-IPV6_MAX_BYTELEN), mod_v6nhl);