Commit Graph

4978 Commits

Author SHA1 Message Date
Donald Sharp
cc9f21da22 *: Change thread->func to return void instead of int
The int return value is never used.  Modify the code
base to just return a void instead.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2022-02-23 19:56:04 -05:00
whichbug
ac3133450d isisd: fix #10505 using base64 encoding
Using base64 instead of the raw string to encode
the binary data.

Signed-off-by: whichbug <whichbug@github.com>
2022-02-22 15:27:30 -05:00
Donald Sharp
4d7aae38ab lib: Fix possible usage of uninited data
assert when if_lookup_address is passed with
a family that is not AF_INET or AF_INET6 as
that we are dead in the water and this is a
dev escape

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2022-02-22 11:02:15 -05:00
Russ White
c07cfc5494
Merge pull request #10571 from rameshabhinay/ospf6_auth_trailer
ospf6d: fix coverity issues.
2022-02-15 13:19:48 -05:00
Russ White
02c29fab18
Merge pull request #10562 from donaldsharp/starv_warn
lib: Save number of times a thread is starved
2022-02-15 12:57:39 -05:00
Abhinay Ramesh
42bfee18c2 ospf6d: fix coverity issues.
Fixed below coverity issues
________________________________________________________________________________________________________
*** CID 1511366:    (TAINTED_SCALAR)
/ospf6d/ospf6_message.c: 2631 in ospf6_make_lsupdate_list()
2625                          + OSPF6_HEADER_SIZE)
2626                         > ospf6_packet_max(on->ospf6_if)) {
2627                             ospf6_fill_header(on->ospf6_if, (*op)->s,
2628                                               length + OSPF6_HEADER_SIZE);
2629                             (*op)->length = length + OSPF6_HEADER_SIZE;
2630                             ospf6_fill_lsupdate_header((*op)->s, *lsa_cnt);
>>>     CID 1511366:    (TAINTED_SCALAR)
>>>     Passing tainted variable "(*op)->length" to a tainted sink.
2631                             ospf6_send_lsupdate(on, NULL, *op);
2632
2633                             /* refresh packet */
2634                             *op = ospf6_packet_new(on->ospf6_if->ifmtu);
2635                             length = OSPF6_LS_UPD_MIN_SIZE;
2636                             *lsa_cnt = 0;
/ospf6d/ospf6_message.c: 2631 in ospf6_make_lsupdate_list()
2625                          + OSPF6_HEADER_SIZE)
2626                         > ospf6_packet_max(on->ospf6_if)) {
2627                             ospf6_fill_header(on->ospf6_if, (*op)->s,
2628                                               length + OSPF6_HEADER_SIZE);
2629                             (*op)->length = length + OSPF6_HEADER_SIZE;
2630                             ospf6_fill_lsupdate_header((*op)->s, *lsa_cnt);
>>>     CID 1511366:    (TAINTED_SCALAR)
>>>     Passing tainted variable "(*op)->length" to a tainted sink.
2631                             ospf6_send_lsupdate(on, NULL, *op);

________________________________________________________________________________________________________
*** CID 1511365:    (TAINTED_SCALAR)
/ospf6d/ospf6_message.c: 2674 in ospf6_make_ls_retrans_list()
2669                             if (on->ospf6_if->state == OSPF6_INTERFACE_POINTTOPOINT)
2670                                     (*op)->dst = allspfrouters6;
2671                             else
2672                                     (*op)->dst = on->linklocal_addr;
2673
>>>     CID 1511365:    (TAINTED_SCALAR)
>>>     Passing tainted variable "(*op)->length" to a tainted sink.
2674                             ospf6_fill_hdr_checksum(on->ospf6_if, *op);
2675                             ospf6_packet_add(on->ospf6_if, *op);
2676                             OSPF6_MESSAGE_WRITE_ON(on->ospf6_if);
/ospf6d/ospf6_message.c: 2674 in ospf6_make_ls_retrans_list()
2669                             if (on->ospf6_if->state == OSPF6_INTERFACE_POINTTOPOINT)
2670                                     (*op)->dst = allspfrouters6;
2671                             else
2672                                     (*op)->dst = on->linklocal_addr;
2673
>>>     CID 1511365:    (TAINTED_SCALAR)
>>>     Passing tainted variable "(*op)->length" to a tainted sink.
2674                             ospf6_fill_hdr_checksum(on->ospf6_if, *op);
2675                             ospf6_packet_add(on->ospf6_if, *op);
2676                             OSPF6_MESSAGE_WRITE_ON(on->ospf6_if);
/ospf6d/ospf6_message.c: 2674 in ospf6_make_ls_retrans_list()
2668                             ospf6_fill_lsupdate_header((*op)->s, *lsa_cnt);
2669                             if (on->ospf6_if->state == OSPF6_INTERFACE_POINTTOPOINT)
2670                                     (*op)->dst = allspfrouters6;
2671                             else
2672                                     (*op)->dst = on->linklocal_addr;
2673
>>>     CID 1511365:    (TAINTED_SCALAR)
>>>     Passing tainted variable "(*op)->length" to a tainted sink.
2674                             ospf6_fill_hdr_checksum(on->ospf6_if, *op);
2675                             ospf6_packet_add(on->ospf6_if, *op);
2676                             OSPF6_MESSAGE_WRITE_ON(on->ospf6_if);

________________________________________________________________________________________________________
*** CID 1511364:  Insecure data handling  (TAINTED_SCALAR)
/ospf6d/ospf6_message.c: 2125 in ospf6_write()
2120                     if (oi->at_data.flags != 0) {
2121                             at_len = ospf6_auth_len_get(oi);
2122                             if (at_len) {
2123                                     iovector[0].iov_len =
2124                                             ntohs(oh->length) + at_len;
>>>     CID 1511364:  Insecure data handling  (TAINTED_SCALAR)
>>>     Passing tainted variable "iovector[0].iov_len" to a tainted sink.
2125                                     ospf6_auth_digest_send(oi->linklocal_addr, oi,
2126                                                            oh, at_len,
2127                                                            iovector[0].iov_len);
2128                             } else {
2129                                     iovector[0].iov_len = ntohs(oh->length);
2130                             }

________________________________________________________________________________________________________
*** CID 1511363:    (DEADCODE)
/ospf6d/ospf6_auth_trailer.c: 275 in ospf6_hash_hmac_sha_digest()
269      case KEYCHAIN_ALGO_HMAC_SHA512:
270     #ifdef CRYPTO_OPENSSL
271              sha512_digest(mes, len, digest);
272     #endif
273              break;
274      case KEYCHAIN_ALGO_NULL:
>>>     CID 1511363:    (DEADCODE)
>>>     Execution cannot reach this statement: "case KEYCHAIN_ALGO_MAX:".
275      case KEYCHAIN_ALGO_MAX:
276      default:

/ospf6d/ospf6_auth_trailer.c: 274 in ospf6_hash_hmac_sha_digest()
269      case KEYCHAIN_ALGO_HMAC_SHA512:
270     #ifdef CRYPTO_OPENSSL
271              sha512_digest(mes, len, digest);
272     #endif
273              break;
>>>     CID 1511363:    (DEADCODE)
>>>     Execution cannot reach this statement: "case KEYCHAIN_ALGO_NULL:".
274      case KEYCHAIN_ALGO_NULL:
275      case KEYCHAIN_ALGO_MAX:
276      default:

________________________________________________________________________________________________________
*** CID 1511362:  Insecure data handling  (TAINTED_SCALAR)
/ospf6d/ospf6_auth_trailer.c: 541 in ospf6_auth_check_digest()
535
536      auth_len = ntohs(ospf6_auth->length);
537
538      memcpy(temp_hash, ospf6_auth->data, hash_len);
539      memcpy(ospf6_auth->data, apad, hash_len);
540
>>>     CID 1511362:  Insecure data handling  (TAINTED_SCALAR)
>>>     Passing tainted variable "oh_len + auth_len + lls_block_len" to a tainted sink.
541      ospf6_auth_update_digest(oi, oh, ospf6_auth, auth_str,
542                               (oh_len + auth_len + lls_block_len),
543                               hash_algo);

________________________________________________________________________________________________________
*** CID 1511361:  Insecure data handling  (TAINTED_SCALAR)
/ospf6d/ospf6_auth_trailer.c: 124 in ospf6_auth_hdr_dump_recv()
118      at_len = length - (oh_len + lls_len);
119      if (at_len > 0) {
120              ospf6_at_hdr =
121                      (struct ospf6_auth_hdr *)((uint8_t *)ospfh + oh_len);
122              at_hdr_len = ntohs(ospf6_at_hdr->length);
123              hash_len = at_hdr_len - OSPF6_AUTH_HDR_MIN_SIZE;
>>>     CID 1511361:  Insecure data handling  (TAINTED_SCALAR)
>>>     Passing tainted variable "hash_len" to a tainted sink.
124              memcpy(temp, ospf6_at_hdr->data, hash_len);
125              temp[hash_len] = '\0';

________________________________________________________________________________________________________
*** CID 1482146:  Insecure data handling  (TAINTED_SCALAR)
/ospf6d/ospf6_message.c: 2787 in ospf6_lsupdate_send_neighbor_now()
2781
2782             if (IS_OSPF6_DEBUG_FLOODING
2783                 || IS_OSPF6_DEBUG_MESSAGE(OSPF6_MESSAGE_TYPE_LSUPDATE, SEND_HDR))
2784                     zlog_debug("%s: Send lsupdate with lsa %s (age %u)", __func__,
2785                                lsa->name, ntohs(lsa->header->age));
2786
>>>     CID 1482146:  Insecure data handling  (TAINTED_SCALAR)
>>>     Passing tainted variable "op->length" to a tainted sink.
2787             ospf6_send_lsupdate(on, NULL, op);

Signed-off-by: Abhinay Ramesh <rabhinay@vmware.com>
2022-02-14 06:36:02 +00:00
ron
1c7c9ba037 lib: not thread off when schedule
Signed-off-by: ron <lyq140hf2006@163.com>
2022-02-11 11:27:11 +08:00
Donald Sharp
1dd08c2243 lib: Save number of times a thread is starved
Add a counter to the number of times a thread is starved from
a timer event and add the output to `show thread cpu`

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2022-02-10 14:10:26 -05:00
Abhinay Ramesh
72000880b0 lib: Changes to support hash algo in keychain.
Problem Statement:
==================
Currently there is no support for configuring hash algorithm in
keychain. 
 
RCA:
====
Not implemented yet.
 
Fix:
====
Changes are done to configure hash algorithm as part of keychain.
which will easy the configuration from modules using keychain.
 
Risk:
=====
Low risk
 
Tests Executed:
===============
Have tested the configuration and unconfiguration flow for newly
implemented CLI.

!
key chain abcd
 key 100
  key-string password
  cryptographic-algorithm sha1
 exit
 key 200
  key-string password
  cryptographic-algorithm sha256
 exit
!

Signed-off-by: Abhinay Ramesh <rabhinay@vmware.com>
2022-02-09 01:49:14 +00:00
Abhinay Ramesh
166f9103d3 lib: Support auto completion of configured keychain.
Problem Statement:
=================
When modules use keychain there is no option for auto completion
of configured keychains.

RCA:
====
Not implemented.

Fix:
====
Changes to support auto completion of configured keychain names.

Risk:
=====
Low risk

Tests Executed:
===============
Have tested auto completion of configured keychain names with newly
implemented auth CLI.

frr(config-if)# ipv6 ospf6 authentication keychain
  KEYCHAIN_NAME  Keychain name
     abcd pqr 12345

Signed-off-by: Abhinay Ramesh <rabhinay@vmware.com>
2022-02-09 01:49:14 +00:00
Donald Sharp
b564209367
Merge pull request #8458 from opensourcerouting/xref-5424
lib: RFC5424 syslog support
2022-02-08 15:56:20 -05:00
Donald Sharp
76802e5209
Merge pull request #10292 from opensourcerouting/pim6-addr-aux
pimd: start tackling IPv6 address operations
2022-02-08 13:09:08 -05:00
Russ White
54e351b86b
Merge pull request #10417 from Orange-OpenSource/TE
Add Constraints Shortest Path First algorithm
2022-02-08 08:26:29 -05:00
Donald Sharp
f0a5b4cb19 lib: Use AF_UNSPEC intead of setting to 0
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2022-02-07 13:21:55 -05:00
Igor Ryzhov
88386db620
Merge pull request #10323 from opensourcerouting/ospf6-lsa-stats
ospf6d: LSA statistics
2022-02-06 21:46:13 +03:00
Jafar Al-Gharaibeh
2da1428ab2
Merge pull request #10501 from donaldsharp/more_zebra_show
More zebra show
2022-02-04 15:13:45 -06:00
Donald Sharp
341743ac5b lib: Update hash.h documentation to warn of a possible crash
Multiple deletions from the hash_walk or hash_iteration calls
during a single invocation of the passed in function can and
will cause the program to crash.  Warn against doing such a
thing.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2022-02-04 12:15:27 -05:00
Donald Sharp
46b48b3302 lib: Add more information to show version
Add to lib/command.c the ability to remember the
release/version/system information and to allow
`show version` to dump some of it.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2022-02-04 10:29:38 -05:00
Olivier Dugeon
fd8e262ab7 lib: Add CSPF Path Computation algorithm
As helper function of Segment Routing Flex Algo or RSVP-TE
add Constrained Shortest Path First algorithm able to compute
path with constraints. Supported constraints are as follow:
 - Standard IGP metric
 - TE IGP metric
 - Delay metric
 - Bandwidth for given Class of Service for bandwidth reservation (RSVP-TE)

Usage of CSPF algorithms is detailed in the doc/developer/cspf.rst file

Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com>
2022-02-02 17:04:12 +01:00
Olivier Dugeon
538f34cb20 lib: Correct bug for TE metric wrong assignement
When link-param is enabled for a given interface, TE metric is automatically
assigned to the metric of the interface. However, the metric of the interface
could be unassigned and keep the default value equal to 0. Thus, if the TE
metric is not explicitely modified within the `link-param metric` statement,
TE metric remains set to 0 which is not a valid value especially when
computing constrainted path.

This patch changes the assignement of the default value of the TE metric.
It is set to the metric of the interface only if the latter is not equal to 0.
TE topotests for OSPF and IS-IS have been adjusted accordingly.

Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com>
2022-02-02 17:04:12 +01:00
Donatas Abraitis
be92fc9f1a bgpd: Convert bgp_addpath_encode_[tr]x() to bool from int
Rename addpath_encode[d] to addpath_capable to be consistent.

Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2022-02-01 13:31:16 +02:00
Igor Ryzhov
3448a75c9d vrrpd: use ipaddr_is_zero when needed
Replace custom implementation or call to ipaddr_isset with a call to
ipaddr_is_zero.

ipaddr_isset is not fully correct, because it's fine to have some
non-zero bytes at the end of the struct in case of IPv4 and the function
doesn't allow that.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2022-01-27 21:05:40 +03:00
Russ White
e48b2fea63
Merge pull request #10411 from idryzhov/if-config-vrf-name
*: do not print vrf name for interface config when using vrf-lite
2022-01-25 11:34:59 -05:00
Russ White
1f2c4ddecb
Merge pull request #10381 from idryzhov/drop-gw-addr
BGP EVPN overlay index fixes and improvements
2022-01-24 07:50:20 -05:00
Igor Ryzhov
788a036fdb *: do not print vrf name for interface config when using vrf-lite
VRF name should not be printed in the config since 574445ec. The update
was done for NB config output but I missed it for regular vty output.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2022-01-24 14:44:05 +03:00
Donald Sharp
e8b3a2f74b lib, zebra: Add ability to tell thread system to ignore late timers
Add a thread_ignore_late_timer(struct thread *thread) function
that allows thread.c to ignore when timers are late to the party.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2022-01-20 11:58:48 -05:00
Donald Sharp
ab01a00176 lib: Figure out if we are being starved for cpu
If a thread timer should have popped CPU_CONSUMED_CHECK
seconds in the past, and we are only handling it now.  Consider
the thread starved and notice it.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2022-01-20 11:56:27 -05:00
Igor Ryzhov
860e740b36 bgpd: replace custom union gw_addr with struct ipaddr
BGP EVPN custom `union gw_addr` is basically the same thing as a common
`struct ipaddr` but it lacks the address family which is needed in some
cases.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2022-01-19 23:13:04 +03:00
Mark Stapp
b542c4a3c7
Merge pull request #10360 from opensourcerouting/clippy-rel-endian
lib/clippy: don't endian-convert twice
2022-01-19 08:58:12 -05:00
Russ White
4ec148523c
Merge pull request #10355 from opensourcerouting/noisy-startup
lib, zebra: make startup less noisy
2022-01-18 11:30:13 -05:00
Russ White
18ed776ca2
Merge pull request #9938 from Orange-OpenSource/isis_ls
isisd: Add Link State Traffic Engineering support
2022-01-18 10:12:08 -05:00
Russ White
05786ac774
Merge pull request #9644 from opensourcerouting/ospf-opaque-attrs
OSPF opaque route attributes
2022-01-18 09:08:38 -05:00
David Lamparter
cfc45e911e lib/clippy: don't endian-convert twice
elf_getdata_rawchunk() already endian-converts; doing it again is, uh,
counterproductive.

Fixes: #10051
Reported-by: Lucian Cristian <lucian.cristian@gmail.com>
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2022-01-18 10:20:34 +01:00
David Lamparter
a6751e2318 pimd: add more dual-family address bits
Another few definitions to aid in dealing with IPv4 and IPv6.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2022-01-17 14:19:11 +01:00
Rafael Zalamena
4e4c027803
Merge pull request #10183 from idryzhov/rework-vrf-rename
*: rework renaming the default VRF
2022-01-17 08:45:12 -03:00
David Lamparter
908e4c85b8 lib: avoid pointless search for built-in IETF YANG
This causes confusing/annoying log messages at startup otherwise:
`YANG model "ietf-inet-types@*" "*@*"not embedded, trying external file`

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2022-01-17 09:46:15 +01:00
David Lamparter
29bb23de31 lib: autodetect systemd/journald log on stdout
systemd sets up environment variables to allow autodetecting and
switching the log format to journald native.  Make use of that for the
stdout logging target.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2022-01-17 00:39:00 +01:00
David Lamparter
1c6261a99e lib: RFC5424 & journald extended syslog target
Not much to say here, user docs are coming up in a separate commit.
RFC5424 and (systemd's) journald allow passing structured key-value
data.  This stuffs the metadata we have available into there.

The "does the system syslogd support RFC5424" question is unfortunately
not easily answered, so we can only give an affirmative answer on NetBSD
5.0+ or FreeBSD 12+.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2022-01-17 00:39:00 +01:00
David Lamparter
603c61656f lib: add frr_early_init hook
To bring up bits that use thread_master before other init happens.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2022-01-17 00:39:00 +01:00
David Lamparter
d948c317c5 build: check for sendmmsg() and struct mmsghdr
These will be used by the RFC5424 log target.

Signed-off-by: David Lamparter <equinox@diac24.net>
2022-01-17 00:38:56 +01:00
Renato Westphal
5b5d66c431 lib, ospfd, ospf6d, zebra: add OSPF opaque route attributes
Update ospfd and ospf6d to send opaque route attributes to
zebra. Those attributes are stored in the RIB and can be viewed
using the "show ip[v6] route" commands (other than that, they are
completely ignored by zebra).

Example:
```
debian# show ip route 192.168.1.0/24
Routing entry for 192.168.1.0/24
  Known via "ospf", distance 110, metric 20, best
  Last update 01:57:08 ago
  * 10.0.1.2, via eth-rt2, weight 1
    OSPF path type        : External-2
    OSPF tag              : 0

debian#
debian# show ip route 192.168.1.0/24 json
{
  "192.168.1.0\/24":[
    {
      "prefix":"192.168.1.0\/24",
      "prefixLen":24,
      "protocol":"ospf",
      "vrfId":0,
      "vrfName":"default",
      "selected":true,
      [snip]
      "ospfPathType":"External-2",
      "ospfTag":"0"
    }
  ]
}
```

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2022-01-15 17:22:27 +01:00
David Lamparter
54929fd38a *: use semicolon after printfrr_ext_autoreg_{p,d}
Mostly to make clang-format not format these to peak ugly.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2022-01-14 13:33:57 +01:00
David Lamparter
f59e688226 lib: add %pTH / %pTHD for printing thread info
Refer to docs in doc/developer for details.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2022-01-14 13:33:57 +01:00
David Lamparter
2c76ba433f lib: add time formatting printfrr exts
Refer to docs in doc/developer for details.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2022-01-14 13:33:57 +01:00
David Lamparter
2c5b4d80ef lib: add s option to pI4/pI6/pIA printfrr
Adding an `s` after these printfrr specifiers replaces 0.0.0.0 / :: in
the output with a star (`*`).  This is primarily intended for use with
multicast, e.g. to print `(*,G)`.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2022-01-14 11:57:46 +01:00
Igor Ryzhov
18461891d3
Merge pull request #10327 from ton31337/fix/reduce_nested_loops
*: Add FOREACH_AFI_SAFI_NSF(afi, safi) macro to reduce nesting
2022-01-13 20:09:50 +03:00
Donald Sharp
21d1ab2dc8
Merge pull request #10324 from anlancs/fix-ospf-stream
lib: fix the right value is returned for fail cases
2022-01-13 09:03:58 -05:00
Donatas Abraitis
df8d723c5f *: Add FOREACH_AFI_SAFI_NSF(afi, safi) macro to reduce nesting
Used for graceful-restart mostly.

Especially for bgp_show_neighbor_graceful_restart_capability_per_afi_safi()

Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2022-01-13 14:29:54 +02:00
Donald Sharp
25b9371c82
Merge pull request #10282 from opensourcerouting/pim6-addr-replace
pimd: `prefix_sg` => `pim_sgaddr`
2022-01-12 15:34:46 -05:00
David Lamparter
d51f8b0f1e pimd: move %pSG4 to %pPSG4
Since this is only used in very few places, moving it out of the way is
reasonable.  (`%pSG` will be pim_sgaddr)

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2022-01-12 18:24:07 +01:00
anlan_cs
10f02a2ac9 lib: fix the right value is returned for fail cases
Currently `bfd_get_peer_info` should return invalid sp->family
and dp->family during fail cases.

Before this fix, in those fail cases `bfd_get_peer_info` maybe
return valid sp->family and dp->family.

This fix ensures all fail cases return invalid sp->family and
dp->family for outside callers.

Signed-off-by: anlan_cs <anlan_cs@tom.com>
2022-01-12 08:08:29 -05:00
David Schweizer
0b11b56abd
ospf6d: add LSA stats to show area json output
Signed-off-by: David Schweizer <dschweizer@opensourcerouting.org>
2022-01-12 12:32:33 +01:00
anlan_cs
03ff0db15d lib: rename one bfd parameter name to reflect real meaning
As to "struct bfd_session_arg", just rename parameter "ttl" to "hops", in order
to  reflect real meaning.

Signed-off-by: anlan_cs <anlan_cs@tom.com>
2022-01-10 08:15:08 -05:00
anlan_cs
8b3fd12cda lib: small debug adjustment for bfd
Just use `__func__` to display function name.

Signed-off-by: anlan_cs <anlan_cs@tom.com>
2022-01-08 06:01:08 -05:00
Igor Ryzhov
ac2cb9bf94 *: rework renaming the default VRF
Currently, it is possible to rename the default VRF either by passing
`-o` option to zebra or by creating a file in `/var/run/netns` and
binding it to `/proc/self/ns/net`.

In both cases, only zebra knows about the rename and other daemons learn
about it only after they connect to zebra. This is a problem, because
daemons may read their config before they connect to zebra. To handle
this rename after the config is read, we have some special code in every
single daemon, which is not very bad but not desirable in my opinion.
But things are getting worse when we need to handle this in northbound
layer as we have to manually rewrite the config nodes. This approach is
already hacky, but still works as every daemon handles its own NB
structures. But it is completely incompatible with the central
management daemon architecture we are aiming for, as mgmtd doesn't even
have a connection with zebra to learn from it. And it shouldn't have it,
because operational state changes should never affect configuration.

To solve the problem and simplify the code, I propose to expand the `-o`
option to all daemons. By using the startup option, we let daemons know
about the rename before they read their configs so we don't need any
special code to deal with it. There's an easy way to pass the option to
all daemons by using `frr_global_options` variable.

Unfortunately, the second way of renaming by creating a file in
`/var/run/netns` is incompatible with the new mgmtd architecture.
Theoretically, we could force daemons to read their configs only after
they connect to zebra, but it means adding even more code to handle a
very specific use-case. And anyway this won't work for mgmtd as it
doesn't have a connection with zebra. So I had to remove this option.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-12-21 22:09:29 +03:00
David Lamparter
b8984d4e90 lib: default VRF may not exist on early exit
If we're exiting before we finished initializing, we can end up trying
to shut down a NULL vrf here.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-12-14 18:12:25 +01:00
David Lamparter
b1dc60f4ab lib: shuffle around command line options
New `FRR_NO_SPLIT_CONFIG` flag for newly added daemons where we're just
rolling without split config and always expect configs to be loaded via
vtysh/integrated config.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-12-14 18:12:20 +01:00
Martin Winter
e574b842a1
bgpd: fix BGP ORF Prefix-length matching
BGP ORF Prefix list incorrectly rejected list with a GE or LE to match the actual
prefix.

Signed-off-by: Martin Winter <mwinter@opensourcerouting.org>
2021-12-14 14:53:53 +01:00
Donatas Abraitis
e69ae079b7
Merge pull request #9899 from Drumato/zebra-srv6-locator-detail-json-support
zebra: Add support for json output in srv6 locator detail command
2021-12-14 09:11:36 +02:00
Igor Ryzhov
fb2e99ef9c lib: routemap config output cleanup
Just a small cleanup to unify the code and remove duplication.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-12-03 21:00:01 +03:00
Russ White
90f88bbc94
Merge pull request #10110 from idryzhov/if-yang-remove-vrf
lib, yang: remove vrf from the interface list key
2021-12-02 08:33:05 -05:00
Donatas Abraitis
e2144103f8
Merge pull request #9878 from pguibert6WIND/resolver_vrf
lib: resolver per vrf support
2021-12-01 08:12:33 +02:00
Olivier Dugeon
8693b4d66e lib: Update Link State functions to handle IPv6
In order to add Link State Traffic Engineering to IS-IS, Link State library
should have been updated:

- Correct Node and Edge RB Tree comparison functions to support key > 32 bits
- Change Subnet RB Tree comparison function to take into account host part of
  the prefix i.e. 10.0.0.1/24 and 10.0.0.2/24 are considered as different
- Add new function to convert IS-IS ISO system ID into Vertex or Edge key that
  take into account Endianness architecture
- Correct Vertex and Edge creation and search function accordingly
- Add extra Adjacency entries in Link State Attributes for IPv6 Segment Routing
- Update send/received and show TED functions accordingly

Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com>
2021-11-30 15:22:28 +01:00
Quentin Young
23b2f11a47
Merge pull request #9798 from abuibrahim/master
fix broken northbound confd
2021-11-30 00:17:28 -05:00
Yamato Sugawara
559f4b2f2a zebra: Add support for json output in srv6 locator detail command
Signed-off-by: Yamato Sugawara <yamato.sugawara@linecorp.com>
2021-11-28 23:53:41 +00:00
Igor Ryzhov
cb3fa0a612
Merge pull request #10124 from ton31337/feature/vty_json 2021-11-29 02:11:29 +03:00
Donatas Abraitis
382dcab318 lib: Convert vty_out to vty_json for JSON
Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2021-11-25 17:50:47 +02:00
Donatas Abraitis
746a6eda2f *: Remove unused variables
Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2021-11-25 17:35:55 +02:00
Donatas Abraitis
a6c8642429 lib: Replace prefix2str for JSON to %pFX
Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2021-11-25 17:31:08 +02:00
Donatas Abraitis
82f191a213 bgpd: Add an ability to match ipv6 next-hop by prefix-list
Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2021-11-24 16:28:31 +02:00
Renato Westphal
959331a339 lib: do not include bgpd headers in route_opaque.h
Duplicate a couple of definitions in order to remove the bgpd
includes from this libfrr header. This is necessary to fix some
name collisions like PREFIX_LIST_IN being defined differently on
multiple daemons (as soon as other daemons start including
route_opaque.h).

Including daemon headers on libfrr headers is a bad practice and
should be avoided whenever possible.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2021-11-23 14:24:07 -03:00
Donatas Abraitis
8f241168b7 lib: Use autocomplete for route-map <name> <action> <seq>
```
exit1-debian-11(config)# route-map ?
  RMAP_NAME  Route map tag
     belekas testas
```

Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2021-11-23 16:10:10 +02:00
Igor Ryzhov
4ac61f7a2a
Merge pull request #10024 from ton31337/feature/match_ipv6_next-hop_access-list
bgpd: match ipv6 next-hop
2021-11-23 16:45:25 +03:00
Donatas Abraitis
bc63ba980f bgpd: Add an ability to match ipv6 next-hop by access-list
Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2021-11-23 13:47:26 +02:00
Igor Ryzhov
574445ecaf lib, yang: remove vrf from the interface list key
This is needed for the following two reasons:

1. To be able to remove the northbound HACK in if_update_to_new_vrf. It
   is totally wrong to rewrite the configuration datastore when some
   operational state changes. It is a hard blocker for storing a
   configuration data in a management daemon which knows nothing about
   the operational state.
2. To allow changing the VRF of the interface using FRR CLI or any other
   frontend in the future. If the VRF is a part of the key, it can't be
   changed. If the VRF is a simple leaf, it becomes possible to change
   it and thus move the interface between VRFs. For now I mark the leaf
   as a "config false" as it's not yet possible to control it from FRR.

But we can't simply remove the VRF from the key, because it is needed to
distinguish interfaces when using netns based VRFs, as it is possible to
have multiple interfaces with the same name in different namespaces. To
handle this, I came up with an idea to store both VRF and an interface
name in the "name" leaf using the pattern "vrfname:ifname". For example,
if there's an interface "eth0" in VRF "red" then its "name" leaf will be
"red:eth0".

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-11-23 12:57:52 +03:00
Philippe Guibert
c742573b67 lib: resolver per vrf support
add a parameter to resolver api that is the vrf identifier. this permits
to make resolution self to each vrf. in case vrf netns backend is used,
this is very practical, since resolution can happen on one netns, while
it is not the case in an other one.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2021-11-23 09:02:23 +01:00
Igor Ryzhov
096f7609f9 *: cleanup ifp->vrf_id
Since f60a1188 we store a pointer to the VRF in the interface structure.
There's no need anymore to store a separate vrf_id field.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-11-22 20:47:23 +03:00
Donald Sharp
9d5a61264a
Merge pull request #10076 from idryzhov/if-is-loopback-or-vrf
*: unify if_is_loopback/if_is_loopback_or_vrf
2021-11-22 12:02:21 -05:00
Donatas Abraitis
039fb41165
Merge pull request #10096 from mjstapp/fix_ted_free
lib: use _safe iteration during link_state/ted cleanup
2021-11-22 15:38:05 +02:00
Igor Ryzhov
03030106ce bgpd, lib: fix inconsistency of match ip/ipv6 next-hop commands
For IPv4 matching, we have "match ip next-hop address A.B.C.D".
For IPv6 matching, we have "match ipv6 next-hop X:X::X:X".

To have consistency, let's add "address" keyword to IPv6 commands.
Old commands are preserved as hidden for backward compatibility.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-11-19 21:11:52 +03:00
Igor Ryzhov
0609190219
Merge pull request #10074 from opensourcerouting/assorted-20211116
lib/vtysh/ospf6d: assorted small bits
2021-11-19 15:43:10 +03:00
Igor Ryzhov
3c52293809
Merge pull request #10092 from ton31337/feature/replace_json_object_string_add_to_json_object_string_addf_for_inet_ntop
*: inet_ntop for JSON output
2021-11-18 22:19:40 +03:00
Donatas Abraitis
4e9a98636f *: Remove unused variables
Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2021-11-18 18:45:41 +02:00
Mark Stapp
bb0e68802d lib: use _safe iteration during link_state/ted cleanup
Use the _safe iterators when cleaning up the link-state module's
vertices, edges, and subnets.

Signed-off-by: Mark Stapp <mstapp@nvidia.com>
2021-11-18 11:23:39 -05:00
zyxwvu Shi
1c1c6c3f2a lib: Do not use sizeof() on size_t errmsg_len.
This prevents caller from getting complete
validation message.

Signed-off-by: zyxwvu Shi <i@shiyc.cn>
2021-11-18 22:44:00 +08:00
Donatas Abraitis
e46a4ac958 lib: Replace inet_ntop to %pI4/6 for JSON outputs
Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2021-11-18 11:35:31 +02:00
Donatas Abraitis
d86cf7aa65
Merge pull request #10084 from opensourcerouting/json-sugar
lib: make JSON output less painful/boilerplate-y
2021-11-18 10:33:52 +02:00
David Lamparter
b5bb6c6764 lib: use json-printf in filter code
(This is mostly just to exercise the code, the actual replacement needs
to be a cocci script.)

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-11-17 16:01:30 +01:00
David Lamparter
ad9df66ce2 lib: use vty_json()
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-11-17 16:01:30 +01:00
David Lamparter
2c4dfddb01 lib: add printfrr to json string helpers
... these should probably have been added ages ago.
`json_object_string_addf(json, "key", "%pFX", prefix)` is super useful.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-11-17 16:01:30 +01:00
David Lamparter
a8dfd147a0 lib: add vty_json() helper
... this is copypasted all over the codebase & should've been a helper
to begin with really.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-11-17 16:01:30 +01:00
Donald Sharp
41e69bb32f
Merge pull request #9852 from opensourcerouting/pim-nht-rework
pimd: make PIM NHT less weird
2021-11-17 09:34:51 -05:00
David Lamparter
4be297235e
Merge pull request #10075 from myloft/fix-chdir-judge 2021-11-17 12:26:23 +01:00
David Lamparter
30f0195d0a lib: fix style misalignment
Just a line that sticks out like a sore thumb.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-11-17 11:33:37 +01:00
David Lamparter
1e9044be8d *: clean up ifp-by-local-address function(s)
Most users of if_lookup_address_exact only cared about whether the
address is any local address.  Split that off into a separate function.

For the users that actually need the ifp - which I'm about to add a few
of - change it to prefer returning interfaces that are UP.

(Function name changed due to slight change in behavior re. UP state, to
avoid possible bugs from this change.)

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-11-17 11:17:44 +01:00
David Lamparter
0beb61abc2 vtysh: dispatch unique-id backtrace cmd properly
i.e. to whoever cares, since some unique IDs (from libfrr) are valid
everywhere but some others (from the daemons) only apply to specific
daemons.

(Default handling aborts on first error, so configuring any unique IDs
that don't exist on the first daemon vtysh connects to just failed
before this.)

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-11-16 18:51:22 +01:00
David Lamparter
dd2c81b8c0 lib: rework vty_check_node_for_xpath_decrement
...by having a flag in struct cmd_node rather than hardcoding it in
`lib/command.c`.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-11-16 18:51:22 +01:00
David Lamparter
88711d8a91 lib: use hash for route-map set/match commands
Why would this be in a vector to loop over with strcmp()'ing each
item...  that just makes no sense.  Use a hash instead.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-11-16 18:51:22 +01:00
Igor Ryzhov
608c887069 *: unify if_is_loopback/if_is_loopback_or_vrf
We should always treat the VRF interface as a loopback. Currently, this
is not the case, because in some old pre-VRF code we use if_is_loopback
instead of if_is_loopback_or_vrf. To avoid any future problems, the
proposal is to rename if_is_loopback_or_vrf to if_is_loopback and use it
everywhere. if_is_loopback is renamed to if_is_loopback_exact in case
it's ever needed, but currently it's not used anywhere.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-11-16 18:07:11 +03:00
Solyn
46cba0d450
zebra: fix chdir judgment to avoid starting failed in a non-existent directory
Signed-off-by: Solyn <admin@iloft.xyz>
2021-11-16 20:46:14 +08:00
Igor Ryzhov
3e51a84a22 lib: rename bfd function to reflect real functionality
Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-11-15 18:16:30 +03:00
Russ White
47af849f95
Merge pull request #9956 from idryzhov/bfd-remove-ttl
lib: remove confusing bfd TTL API
2021-11-14 12:24:28 -05:00
Donald Sharp
045e023549
Merge pull request #10032 from opensourcerouting/build-fix-20211111
build: assorted build system improvements, 2021-11 edition
2021-11-13 10:10:59 -05:00
Jafar Al-Gharaibeh
3357afaa74
Merge pull request #10036 from donaldsharp/finally_frr
Finally frr
2021-11-12 21:35:27 -06:00
Ruslan Babayev
fc3ebe1235 lib: confd: fix format-truncation warnings
Signed-off-by: Ruslan Babayev <ruslan@babayev.com>
2021-11-11 23:05:46 -08:00
Ruslan Babayev
7f88892d96 lib: confd: fix non-void return-type warning
Signed-off-by: Ruslan Babayev <ruslan@babayev.com>
2021-11-11 23:05:46 -08:00
Ruslan Babayev
722e430fd5 lib: confd: fix compilation broken with libyang2
Fixes the following compilation errors:

In file included from /home/ruslan/sdk/sysroots/corei7-64-poky-linux/usr/include/libyang/tree_data.h:30,
                 from /home/ruslan/sdk/sysroots/corei7-64-poky-linux/usr/include/libyang/context.h:22,
                 from /home/ruslan/sdk/sysroots/corei7-64-poky-linux/usr/include/libyang/libyang.h:24,
                 from ../../src/frr/lib/yang.h:25,
                 from ../../src/frr/lib/northbound.h:27,
                 from ../../src/frr/lib/vty.h:36,
                 from ../../src/frr/lib/ferr.h:28,
                 from ../../src/frr/lib/lib_errors.h:24,
                 from ../../src/frr/lib/northbound_confd.c:23:
../../src/frr/lib/northbound_confd.c: In function 'frr_confd_init_cdb':
../../src/frr/lib/northbound_confd.c:533:28: error: 'const struct lys_module' has no member named 'data'
  533 |   LY_LIST_FOR (module->info->data, snode) {
      |                            ^~
../../src/frr/lib/northbound_confd.c: In function 'frr_confd_data_get_next_object':
../../src/frr/lib/northbound_confd.c:921:3: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
  921 |   LY_LIST_FOR (lysc_node_child(nb_node->snode), child) {
      |   ^~~~~~~~~~~

Signed-off-by: Ruslan Babayev <ruslan@babayev.com>
2021-11-11 23:05:46 -08:00
Donald Sharp
13576f45f8
Merge pull request #9981 from idryzhov/fix-vrf-delete
lib: fix vrf deletion when the last interface is deleted
2021-11-11 18:41:02 -05:00
Donald Sharp
b72aae2e04 *: Cleanup some documentation from quagga->frr
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2021-11-11 14:41:27 -05:00
Donald Sharp
e36f61b507 *: Rename quagga_timestamp with frr_timestamp
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2021-11-11 14:41:27 -05:00
Donald Sharp
7cc91e67a3 *: Convert quagga_signal_X to frr_signal_X
Naming functions/data structures more appropriately for
the project we are actually in.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2021-11-11 14:41:27 -05:00
David Lamparter
f642358837 build: fix duplicate yang.c file inclusions
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-11-11 15:49:40 +01:00
Donald Sharp
7a8ce9d56d *: use compiler.h MIN/MAX macros instead of everyone having one
We had various forms of min/max macros across multiple daemons
all of which duplicated what we have in compiler.h.  Convert
everyone to use the `correct` ones

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2021-11-11 09:39:52 -05:00
David Lamparter
3bd7df45a2 build: link libcrypt & libdl to libfrr only
They're not needed elsewhere.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-11-11 15:29:48 +01:00
Russ White
eda02ab9da
Merge pull request #10025 from opensourcerouting/xref-backtrace
lib: backtraces for specific log messages
2021-11-11 08:08:19 -05:00
Russ White
b761cb131a
Merge pull request #9864 from ton31337/feature/access_list_autocomplete
lib: Add autocomplete for access-lists
2021-11-11 08:03:33 -05:00
Igor Ryzhov
ce27a13e90 lib: fix vrf deletion when the last interface is deleted
Currently, we automatically delete an inactive VRF when its last
interface is deleted. This code introduces a couple of crashes because
of the following problems:
- vrf_delete is called before calling if_del hook, so daemons may try to
  dereference an ifp->vrf pointer which is freed
- in if_terminate, we continue to use the VRF in the loop condition
  after the last interface is deleted

This check is needed only when the interface is deleted by the user,
because if the interface is deleted by the system, VRF must still exist
in the system. Move the check to appropriate places to fix crashes.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-11-11 14:57:59 +03:00
Igor Ryzhov
92f85e656b lib: remove confusing bfd TTL API
There are two APIs to control the expected number of hops for a BFD
session – `bfd_sess_set_mininum_ttl` and `bfd_sess_set_hop_count`.
The former is very confusing, as it takes an expected TTL in the
BFD packet which is actually a protocol internal value. The latter is
simple and straightforward – it takes an expected number of hops, which
is always 1 for single-hop and >1 for multi-hop.

As the former API is not used anywhere, just remove it to avoid any
confusion.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-11-11 14:56:04 +03:00
David Lamparter
3942ee1f7b lib: fix elf_py TLS section handling
... need to ignore TLS sections, their address is effectively
meaningless but can overlap other sections we actually need to access.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-11-10 15:30:56 +01:00
David Lamparter
8d4e934b08 lib: avoid include loop with assert.h
`assert.h` -> `xref.h` -> `typesafe.h` -> `assert.h`

Might be possible to do this more cleanly some way, but that way is not
obvious, so here's the "simple & dumb" approach.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-11-10 12:36:50 +01:00
David Lamparter
ef990bd94b lib: add debug uid XXXXX-XXXXX backtrace
Looks much prettier if `libunwind` is available, but works with glibc or
libexecinfo's `backtrace()` too.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-11-10 12:36:50 +01:00
David Lamparter
4894e9c12a lib: stuff xrefs into a tree for lookup
... so we can actually access by UID without searching the entire list.

Signed-off-by: David Lamparter <equinox@diac24.net>
2021-11-10 10:39:17 +01:00
David Lamparter
b0993fb201 lib: add missing include in typerb.h
The RB-tree macros use memset(), so we need to #include <string.h>

Signed-off-by: David Lamparter <equinox@diac24.net>
2021-11-10 10:39:17 +01:00
David Lamparter
14ae4f17a8 lib: remove vector_get_index()
... its only purpose was to serve as a footgun, and all such uses have
been eliminated now.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-11-08 14:07:30 +01:00
David Lamparter
faf079ff7e lib: fix c-ares thread misuse
The `struct thread **ref` that the thread code takes is written to and
needs to stay valid over the lifetime of a thread.  This does not hold
up if thread pointers are directly put in a `vector` since adding items
to a `vector` may reallocate the entire array.  The thread code would
then write to a now-invalid `ref`, potentially corrupting entirely
unrelated data.

This should be extremely rare to trigger in practice since we only use
one c-ares channel, which will likely only ever use one fd, so the
vector is never resized.  That said, c-ares using only one fd is just
plain fragile luck.

Either way, fix this by creating a resolver_fd tracking struct, and
clean up the code while we're at it.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-11-08 14:06:21 +01:00
David Lamparter
26ae7cc219 lib: keep vty listeners in a proper struct & list
Makes a bit more sense than the odd vector stuff.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-11-06 21:11:40 +01:00
David Lamparter
43dd8cafa3 lib: replace vtyvec/vtyshvec with lists
These are just used to iterate over active vty sessions, a vector is a
weird choice there.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-11-06 21:11:40 +01:00
David Lamparter
69b089fbfd lib: remove unused vty_log() functions
These had no remaining users for a while now.  The logging backend has
its own list of receivers.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-11-06 21:11:40 +01:00
Russ White
208a07a8b8
Merge pull request #9972 from opensourcerouting/bfd-bgp-fixes
bfdd,bgpd: fix some integration bugs
2021-11-05 17:31:29 -04:00
Russ White
ed79d896b2
Merge pull request #9833 from idryzhov/cleanup-if-by-index-all-vrf
*: fix usage of if_lookup_by_index_all_vrf
2021-11-05 15:17:31 -04:00
Rafael Zalamena
ca30ac7fc3 lib: constify read only parameters
Constify some BFD library function parameters to signalize they are
not going to get modified.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2021-11-04 08:01:28 -03:00
Renato Westphal
ae09457333 lib: fix BFD IPv6 session address change
Pass the correct family type and remove unneeded casts.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2021-11-04 08:00:30 -03:00
Igor Ryzhov
d2dbaf3b5e lib: fix crash when terminating inactive VRFs
If the VRF is not enabled, if_terminate deletes the VRF after the last
interface is removed from it. Therefore daemons crash on the subsequent
call to vrf_delete. We should call vrf_delete only for enabled VRFs.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-11-03 12:53:02 +03:00
Igor Ryzhov
9acc98c865 zebra: fix stale pointer when netns is deleted
When the netns is deleted, we should always clear the vrf->ns_ctxt
pointer. Currently, it is not cleared when there are interfaces in the
netns at the time of deletion.

If the netns is re-created, zebra crashes because it tries to use the
stale pointer.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-11-03 11:11:15 +03:00
Donald Sharp
821a877fd7 lib: Return Null when we have an empty string for script name
The script entries were being stored in a hash lookup with
the script name a pre-defined array of characters.  The hash
lookup is succeeding since it is auto-installed at script
start time irrelevant if there is a handler function.

Modify the code so that if the scriptname is an empty
string "\0" just return a NULL so that zebra does
not attempt to actually load up the script

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2021-11-01 07:29:10 -04:00
Donatas Abraitis
c60dec369a lib: Add autocomplete for access-lists
Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2021-10-31 20:26:06 +02:00
Igor Ryzhov
0373909a5f
Merge pull request #9863 from ton31337/feature/prefix-list_autocomplete
lib: Add autocomplete for prefix-list under route-maps
2021-10-29 13:30:04 +03:00
Igor Ryzhov
35a8ebb5db
Merge pull request #9879 from Orange-OpenSource/link_state
lib: Fix comparison function in link_state.c
2021-10-29 13:26:23 +03:00
Olivier Dugeon
f4157b4f6e lib: Fix comparison function in link_state.c
ls_node_same, ls_attributes_same and ls_prefix_same are not producing expected
result due to a wrong usage of memcmp. In addition, if respective structures
are not initialized with 0, there is a risk that the comparison failed.

This patch correct usage of memcmp and expand comparison to each invidual
parameters of the respective structure for safer result.

Signed-off-by: Olivier Dugeon <olivier.dugeon@orange.com>
2021-10-29 10:16:12 +02:00
Igor Ryzhov
35367f0350 lib: make if_lookup_by_index_all_vrf internal
This function doesn't work correctly with netns VRF backend as the same
index may be used in multiple netns simultaneously. So let's hide it
from the public API to reduce temptation to use it instead of writing
the correct code.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-10-28 18:54:46 +03:00
Igor Ryzhov
8d62b34195 lib: remove wrong setting of interface configured flag
The fact that the interface name is used in some nexthop config doesn't
mean that the interface is configured.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-10-28 18:54:46 +03:00
Donatas Abraitis
943224a13a lib: Add autocomplete for prefix-list under route-maps
```
exit1-debian-9(config-route-map)# match ip route-source prefix-list ?
  <cr>
  PREFIXLIST_NAME  IP prefix-list name
     p1 p2
```

Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2021-10-28 14:01:13 +03:00
Russ White
f727c6ae8a
Merge pull request #9837 from idryzhov/cleanup-if-by-name-vrf-all
*: fix usage of if_lookup_by_name_all_vrf
2021-10-27 15:29:39 -04:00
Quentin Young
0c124f75db
Merge pull request #9440 from dlqs/dplanehook2 2021-10-26 15:26:32 -04:00
Mark Stapp
d127998785
Merge pull request #9846 from idryzhov/lib-zebra-netns
lib: move zebra-only netns stuff to zebra
2021-10-26 12:50:26 -04:00
Mark Stapp
697257179d
Merge pull request #9820 from idryzhov/if-nb-config
*: fix interface config write in NB-converted daemons
2021-10-26 11:50:05 -04:00
Russ White
a2b52cbeb4
Merge pull request #9854 from opensourcerouting/zapi-call-table
*: convert zclient callbacks to table
2021-10-26 11:33:44 -04:00
Hiroki Shirokura
8563b9722a lib: fix srv6 route hardcode with BGP
zclient_send_localsid is called by various routing protocol daemons. To set the
srv6 endpoint function. Fix a hard-coded error in the initial implementation.
Before this PR, the srv6 function will be registered to zebra as a BGP route
even if isisd executes zclient_send_localsid.

Signed-off-by: Hiroki Shirokura <hiroki.shirokura@linecorp.com>
2021-10-25 23:38:42 +00:00
Donald Sharp
d9654571f9
Merge pull request #9316 from ton31337/fix/send_best_path_reason_for_zebra
bgpd: Send BGP best path reason to Zebra
2021-10-25 11:09:20 -04:00
Igor Ryzhov
104fd76738 *: fix interface config write in NB-converted daemons
When writing the config from the NB-converted daemon, we must not rely
on the operational data. This commit changes the output of the interface
configuration to use only config data. As the code is the same for all
daemons, move it to the lib and remove all the duplicated code.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-10-25 15:31:07 +03:00
Donald Sharp
6f354338f9
Merge pull request #9824 from idryzhov/nb-cli-const-lyd-node
lib: northbound cli show/cmd functions must not modify data nodes
2021-10-25 07:55:39 -04:00
Jafar Al-Gharaibeh
63da89db77
Merge pull request #9742 from elimbaum/add-vlan-actions
pbrd: add vlan actions to vty
2021-10-23 00:06:16 -05:00
Mark Stapp
036b746570
Merge pull request #9765 from idryzhov/lib-bool-thread-add
lib: change thread_add_* API
2021-10-22 09:59:54 -04:00
ewlumpkin
03bad95aa4 lib: finish fixing spelling in lib files
Signed-off-by: ewlumpkin <ewlumpkin@gmail.com>
2021-10-22 03:06:16 +00:00
Donald Sharp
3c8161eaa8
Merge pull request #9843 from opensourcerouting/vtysh-startup-cost
vtysh: improve startup time by ca. ×6
2021-10-20 18:52:00 -04:00
Igor Ryzhov
ee1455dd98 lib: change thread_add_* API
Do not return pointer to the newly created thread from various thread_add
functions. This should prevent developers from storing a thread pointer
into some variable without letting the lib know that the pointer is
stored. When the lib doesn't know that the pointer is stored, it doesn't
prevent rescheduling and it can lead to hard to find bugs. If someone
wants to store the pointer, they should pass a double pointer as the last
argument.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-10-20 20:07:15 +03:00
Donald Sharp
a505383d6a lib: Add a thread_is_scheduled function
The function thread_is_scheduled allows us to know if
the particular thread is scheduled for execution or not.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2021-10-20 08:28:52 -04:00
Mark Stapp
52e458d922
Merge pull request #9766 from opensourcerouting/typesafe-member-nhrp-zap
lib: add typesafe membership-test functions
2021-10-20 08:13:17 -04:00
David Lamparter
a243d1db93 *: convert zclient callbacks to table
This removes a giant `switch { }` block from lib/zclient.c and
harmonizes all zclient callback function types to be the same (some had
a subset of the args, some had a void return, now they all have
ZAPI_CALLBACK_ARGS and int return.)

Apart from getting rid of the giant switch, this is a minor security
benefit since the function pointers are now in a `const` array, so they
can't be overwritten by e.g. heap overflows for code execution anymore.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-10-20 13:28:46 +02:00
Donald Lee
1247efcce4 zebra: Add dplane hook point
Signed-off-by: Donald Lee <dlqs@gmx.com>
2021-10-20 00:56:00 +08:00
Donald Lee
a3ef7ae835 lib: Add frrscript names hash
Signed-off-by: Donald Lee <dlqs@gmx.com>
2021-10-20 00:56:00 +08:00
Donald Lee
263951c1be lib: Register encoders/decoders for dplane hook
These are for encoding the dplane ctx object. The decoders are noops.

Signed-off-by: Donald Lee <dlqs@gmx.com>
2021-10-20 00:56:00 +08:00
Donald Lee
9b851b74b0 lib: Add encoder/decoder for nexthop/nexthop group
Signed-off-by: Donald Lee <dlqs@gmx.com>
2021-10-20 00:56:00 +08:00
Donald Lee
e6f42b94c6 lib: Add encoders/decoders for ipaddr/ethaddr
Signed-off-by: Donald Lee <dlqs@gmx.com>
2021-10-20 00:56:00 +08:00
David Lamparter
40ee228da9 lib: add unsorted typesafe_anywhere()
*_anywhere(item) returns whether an item is on _any_ container.  Only
available for unsorted containers for now.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-10-19 14:55:39 +02:00
David Lamparter
d259ca0989 lib: use sentinel for single-linked lists
Using a non-NULL sentinel allows distinguishing between "end of list"
and "item not on any list".  It's a compare either way, just the value
is different.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-10-19 14:55:39 +02:00
David Lamparter
f45897e45c lib: typesafe *_member()
This provides a "is this item on this list" check, which may or may not
be faster than using *_find() for the same purpose.  (If the container
has no faster way of doing it, it falls back to using *_find().)

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-10-19 14:55:39 +02:00
David Lamparter
4a1b3289c7 lib: null out deleted pointers in typesafe containers
Some of the typesafe containers didn't null out their innards of items
after an item was deleted or popped off the container.  This is both a
bit unsafe as well as hinders the upcoming _member() from working
efficiently.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-10-19 14:55:39 +02:00
Igor Ryzhov
f60a11883c lib: allow to create interfaces in non-existing VRFs
It allows FRR to read the interface config even when the necessary VRFs
are not yet created and interfaces are in "wrong" VRFs. Currently, such
config is rejected.

For VRF-lite backend, we don't care at all about the VRF of the inactive
interface. When the interface is created in the OS and becomes active,
we always use its actual VRF instead of the configured one. So there's
no need to reject the config.

For netns backend, we may have multiple interfaces with the same name in
different VRFs. So we care about the VRF of inactive interfaces. And we
must allow to preconfigure the interface in a VRF even before it is
moved to the corresponding netns. From now on, we allow to create
multiple configs for the same interface name in different VRFs and
the necessary config is applied once the OS interface is moved to the
corresponding netns.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-10-19 15:29:51 +03:00
Igor Ryzhov
62d89c648b lib: move zebra-only netns stuff to zebra
When something is used only from zebra and part of its description is
"should be called from zebra only" then it belongs to zebra, not lib.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-10-19 00:16:10 +03:00
David Lamparter
14c39974bb lib: keep element count in vector code
... to speed up vector_empty_slot() among other things.

Behavior should be 100% identical to previous.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-10-18 19:48:11 +02:00
David Lamparter
0e06eb8b2e vtysh: defer CLI tree building
We don't need the CLI tree until we actually enter the node.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-10-18 19:48:11 +02:00
David Lamparter
8005767b2e lib: assign CLI varnames while parsing
... rather than running a costly extra pass across the finished tree.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-10-18 19:48:11 +02:00
Donatas Abraitis
840b90f501
Merge pull request #9828 from idryzhov/if-lookup-optimize
lib: optimize if_lookup_by_name_all_vrf
2021-10-16 11:17:57 +03:00
Igor Ryzhov
0df2e1888b lib: make if_lookup_by_name_all_vrf internal
This function doesn't work correctly with netns VRF backend as the same
ifname may be used in multiple netns simultaneously. So let's hide it
from the public API to reduce temptation to use it instead of writing
the correct code.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-10-15 03:44:42 +03:00
Igor Ryzhov
5d8694aee7 lib: remove wrong setting of interface configured flag
The fact that the interface name is used in some nexthop config doesn't
mean that the interface is configured.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-10-15 03:42:52 +03:00
Donatas Abraitis
1d7260a1b5 bgpd: Send BGP best path reason to Zebra
```
exit1-debian-9# show ip route 172.16.16.1/32
Routing entry for 172.16.16.1/32
  Known via "bgp", distance 20, metric 0, best
  Last update 00:00:28 ago
  * 192.168.0.2, via eth1, weight 1
    AS-Path          : 65003
    Communities      : first 65001:2 65001:3
    Large-Communities: 65001:1:1 65001:1:2 65001:1:3
    Selection reason : First path received
```

Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2021-10-14 16:52:47 +03:00
Donatas Abraitis
7b3e821076
Merge pull request #9817 from donaldsharp/link_type_ordering
lib: Add missing enum values in switch statement for if_link_type_str
2021-10-14 16:25:02 +03:00
Donald Sharp
c6c39c05b5
Merge pull request #9684 from opensourcerouting/printfrr-false-positive
*: `frr-format` with unmodified GCC
2021-10-14 07:34:20 -04:00
Igor Ryzhov
d555177021
Merge pull request #9751 from ewlumpkin/comment_spelling_fixes
lib: fix spelling nits in more lib files' comments
2021-10-14 02:05:44 +03:00
David Lamparter
c5726f0314
Merge pull request #9676 from donaldsharp/import_register 2021-10-13 22:28:03 +02:00
Igor Ryzhov
5393f4db3f lib: optimize if_lookup_by_name_all_vrf
We already have a VRF pointer, no need to search for it again.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-10-13 23:23:41 +03:00
Igor Ryzhov
2560505196 lib: northbound cli show/cmd functions must not modify data nodes
To ensure this, add a const modifier to functions' arguments. Would be
great do this initially and avoid this large code change, but better
late than never.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-10-13 20:12:35 +03:00
Donald Sharp
ba62a5c522 lib: Add missing enum values in switch statement for if_link_type_str
The switch statement over `enum zebra_link_type` had a default
and FRR was missing a few of the pre-defined types we cared about.
Remove the default statement and add the missing values.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2021-10-13 07:58:37 -04:00
Donatas Abraitis
314479e114
Merge pull request #9715 from idryzhov/cleanup-number-named-acl
*: cleanup number-named access-lists in CLI
2021-10-13 10:00:43 +03:00
Russ White
8274736a0d
Merge pull request #9764 from idryzhov/thread-add-local
*: don't pass pointers to a local variables to thread_add_*
2021-10-08 13:54:23 -04:00
Igor Ryzhov
7e86999140 *: cleanup number-named access-lists in CLI
There's no more difference between number-named and word-named access-lists.
This commit removes separate arguments for number-named ACLs from CLI.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-10-08 19:25:41 +03:00
David Lamparter
1c50c7243f
Merge pull request #9345 from mjstapp/fix_lib_zmq_free 2021-10-07 15:20:19 +02:00
Eli Baum
d70a31a3ef pbrd: add vlan actions to vty
Signed-off-by: Eli Baum <ebaum@mitre.org>
2021-10-07 09:14:59 -04:00
Igor Ryzhov
7640e3c60b *: don't pass pointers to a local variables to thread_add_*
We should never pass pointers to local variables to thread_add_* family.
When an event is executed, the library writes into this pointer, which
means it writes into some random memory on a stack.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-10-07 16:01:03 +03:00
Igor Ryzhov
72618ba82a lib: fix incorrect thread management
The current code passes an address of a local variable to `thread_add_read`
which stores it into `thread->ref` by the lib. The next time the thread
callback is executed, the lib stores NULL into the `thread->ref` which
means it writes into some random memory on the stack.

To fix this, we should pass a pointer to the vector entry to the lib.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-10-06 19:13:12 +03:00
Russ White
a3232e63e6
Merge pull request #9733 from opensourcerouting/grpc-fix-missing
lib: fix gRPC crash on missing YANG node
2021-10-05 19:24:34 -04:00
ewlumpkin
214d8a60e1 lib: fix spelling nits in more lib files
Signed-off-by: ewlumpkin <ewlumpkin@gmail.com>
2021-10-05 21:42:57 +00:00
Rafael Zalamena
0f538858c2 lib: prevent gRPC assert on missing YANG node
`yang_dnode_get` will `assert` if no YANG node/model exist, so lets test for
its existence first before trying to access it.

This `assert` is only acceptable for internal FRR usage otherwise we
might miss typos or unmatching YANG models nodes/leaves. For gRPC usage
we should let users attempt to use non existing models without
`assert`ing.

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
2021-10-05 10:22:27 -03:00
ewlumpkin
81eb8fc749 lib: fix spelling nits in command.h
Signed-off-by: ewlumpkin <ewlumpkin@gmail.com>
2021-10-05 03:21:50 +00:00
David Lamparter
a89bae26f7
Merge pull request #9560 from LabNConsulting/ziemba/frrmod_load-error-messages
frrmod_load(): fix error messages
2021-09-29 14:35:35 +02:00
David Lamparter
f62de63c6a *: frr-format with unmodified GCC
Since there's very few locations where the `frr-format` actually prints
false positive warnings, consensus seems to be to just work around the
false positives even if the code is correct.

In fact, there is only one pattern of false positives currently, in
`bfdd/dplane.c` which does `vty_out("%"PRIu64, (uint64_t)be64toh(...))`.
The workaround/fix for this is a replacement `be64toh` whose type is
always `uint64_t` regardless of what OS we're on, making the cast
unnecessary.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2021-09-28 11:20:32 +02:00
Donald Sharp
027db46917 lib, zebra: Send safi for rnh resolution
Pass down the safi for when we need address
resolution.  At this point in time we are
hard coding the safi to SAFI_UNICAST.
Future commits will take advantage of this.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2021-09-27 15:26:05 -04:00
Donald Sharp
6cd9a93ddd zebra: Attempt to clarify variable names as they are used
Cleanup the poorly implemented variable names so that we can
understand what is going on a bit better.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2021-09-27 12:38:08 -04:00
Donald Sharp
3d174ce08d *: Remove the ZEBRA_IMPORT_ROUTE_XXX zapi messages
These are no longer really needed.  The client just needs
to call nexthop resolution instead.

So let's remove the zapi types.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
2021-09-27 12:38:08 -04:00