Commit graph

150 commits

Author SHA1 Message Date
Donald Sharp 35518f5419 lib: make is_default_host_route use a const struct prefix
Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2020-03-22 17:14:32 -04:00
Kishore Aramalla c6ec0c745a bgpd: RFC compliance wrt invalid RMAC, GWIP, ESI and VNI
A route where ESI, GW IP, MAC and Label are all zero at the same time SHOULD
be treat-as-withdraw.
Invalid MAC addresses are broadcast or multicast MAC addresses. The route
MUST be treat-as-withdraw in case of an invalid MAC address.

As FRR support Ethernet NVO Tunnels only.
Route will be withdrawn when ESI, GW IP and MAC are zero or Invalid MAC

Test cases:
1) ET-5 route with valid RMAC extended community
2) ET-5 route no RMAC extended community
3) ET-5 route with Multicast MAC in RMAC extended community
4) ET-5 route with Broadcast MAC in RMAC extended community

Signed-off-by: Kishore Aramalla <karamalla@vmware.com>
2020-02-11 12:36:50 -08:00
Russ White b27b58be24
Merge pull request #4773 from thozza/31-prefix-bcast-addr
ipv4_broadcast_addr() didn't comply with RFC3021
2020-01-28 11:42:45 -05:00
David Lamparter 25d8623340 lib/prefix: flip the bitrot compost
Signed-off-by: David Lamparter <equinox@diac24.net>
2019-12-14 12:28:18 +01:00
Donald Sharp 63265b5c1f *: Convert prefix_free to double pointer
Have the prefix_free code take a double pointer to free the data.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-11-02 16:13:44 -04:00
Lakshman Krishnamoorthy 44c6974748 bgpd: Adding new bgp evpn cli's for ip-prefix lookup
Implement CLIs for the following, to filter for a prefix within
evpn type 5 route
1) show bgp l2vpn evpn A.B.C.D
2) show bgp l2vpn evpn A.B.C.D json
3) show bgp l2vpn evpn A.B.C.D/M
4) show bgp l2vpn evpn A.B.C.D/M json
5) show bgp l2vpn evpn X:X::X:X
6) show bgp l2vpn evpn X:X::X:X json
7) show bgp l2vpn evpn X:X::X:X/M
8) show bgp l2vpn evpn X:X::X:X/M json

Sample output provided here: https://github.com/FRRouting/frr/pull/4850

Signed-off-by: Lakshman Krishnamoorthy <lkrishnamoor@vmware.com>
2019-09-27 10:58:46 -07:00
Mark Stapp a9e08ebce1 lib: use const in prefix_mac2str
Use const for mac pointer.

Signed-off-by: Mark Stapp <mjs@voltanet.io>
2019-08-23 10:09:38 -04:00
Tomas Hozza 2d48474e03 lib/prefix.c: ipv4_broadcast_addr() didn't comply with RFC3021
The function ipv4_broadcast_addr() does not calculate correct broadcast
addresses for point-to-point connections with prefix 31. RFC3021
section 3.3 [1] specifies:

"The 255.255.255.255 IP broadcast address MUST be used for broadcast
Address Mask Replies in point-to-point links with 31-bit subnet masks"

The issue causes Zebra to print the following warning when IPv4 address
with 31 prefix (e.g. 192.168.222.240/31) is configured on a network
interface:

ZEBRA: [EC 4043309141] warning: interface VNS broadcast addr 255.255.255.255/31 != calculated 192.168.222.241, routing protocols may malfunction

The issue has been originally found in Quagga [2], but it is present also
in FRR.

[1] https://tools.ietf.org/html/rfc3021#section-3.3
[2] https://bugzilla.redhat.com/show_bug.cgi?id=1713449

Signed-off-by: Tomas Hozza <thozza@redhat.com>
2019-08-05 09:24:29 +02:00
David Lamparter 4937287fb9 lib: fix prefix_copy() for clang-SA
https://bugs.llvm.org/show_bug.cgi?id=42811

Signed-off-by: David Lamparter <equinox@diac24.net>
2019-07-29 15:49:49 +02:00
David Lamparter 9c3a217137 lib: use some more transparent unions for prefixes
... so we can pass prefix_ipv4/prefix_ipv6 in.

Signed-off-by: David Lamparter <equinox@diac24.net>
2019-07-28 09:26:21 +02:00
Donald Sharp 62b4b3b68d lib: Make prefix_hash_key accept a const
We should not be modifying the pointer for the prefix_hash_key
function, make it a const so that we can use it elsewhere.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-05-02 16:21:38 -04:00
Lou Berger e8b9ad5cdd
Revert "Zebra diet" 2019-05-02 06:54:59 -04:00
Donald Sharp 6701b1b7e7 lib: Make prefix_hash_key accept a const
We should not be modifying the pointer for the prefix_hash_key
function, make it a const so that we can use it elsewhere.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2019-05-01 20:28:57 -04:00
Anuradha Karuppiah fef327404f lib: two extra bytes were being allocated for the SG string
Fixup in response to Jafar's review comments.

This is actually old code moved in from pimd to lib. But the fixup does
make sense.

Signed-off-by: Anuradha Karuppiah <anuradhak@cumulusnetworks.com>
2019-04-21 07:24:20 -07:00
Anuradha Karuppiah c6b6b53b29 lib: move SG prefix2str APIs from pimd to lib
This is to allow zebra to use these APIs instead of re-defining.

Signed-off-by: Anuradha Karuppiah <anuradhak@cumulusnetworks.com>
2019-04-20 08:33:20 -07:00
Chirag Shah 1eb6c3eae6 *: do not register nexthop 0.0.0.0 to nht
Avoid tracking 0.0.0.0/32 nexthop with RIB.

When routes are aggregated,
the originate of the route becomes self.
Do not track nexthop self (0.0.0.0) with rib.

Ticket: CM-24248
Testing Done:

Before fix-

tor-11# show ip nht vrf all

VRF blue:
0.0.0.0
 unresolved
 Client list: bgp(fd 16)

VRF default:

VRF green:

VRF magenta:
0.0.0.0
 unresolved
 Client list: bgp(fd 16)

After fix-

tor-11# show ip nht vrf all

VRF blue:

VRF default:

VRF green:

VRF magenta:

Signed-off-by: Chirag Shah <chirag@cumulusnetworks.com>
2019-04-03 11:17:57 -07:00
Renato Westphal 5e2444690b lib: add extern "C" {} blocks to all libfrr headers
These are necessary to use functions defined in these headers from C++.

Signed-off-by: David Lamparter <equinox@diac24.net>
Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2019-02-11 22:34:12 -02:00
David Lamparter be566e4e45 lib: make union prefixptr C++-compatible
Add a no-op conversion constructor to tell C++ that union prefixptr
accepts any of its member types.

Signed-off-by: David Lamparter <equinox@diac24.net>
2019-02-11 15:49:49 -02:00
Renato Westphal d8e331eb0e
Merge pull request #3180 from qlyoung/prefixlen-u8-to-u16
lib: convert prefixlen to 16-bit integer
2019-01-15 00:39:39 -02:00
Donald Sharp 6a923ca462 lib: Add another 32 bit accessor to the prefix data structure
It would be nice to have the ability to access the prefix data structure
address as a block of 4 uint32_t's.  This will allow me to easily/quickly
update the v6 address by 1.  This will be used in subsuquent commits.

Signed-off-by:  Donald Sharp <sharpd@cumulusnetworks.com>
2019-01-10 19:26:31 -05:00
Quentin Young 61be6e94ab bgpd, lib: few more prefixlen updated
* Cast when assigning should be to uint16_t
* Restored comment documenting strange behavior
* Further increased PREFIX_STRLEN to 80 chars

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2018-10-25 20:25:36 +00:00
Quentin Young f93eee447e lib: convert prefixlen to 16-bit integer
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2018-10-15 15:45:19 +00:00
paco 5d5ba0185d
bgpd, lib, ospfd, zebra: all_digit moved to frrstr
This solves a pending FIXME

Signed-off-by: F. Aragon <paco@voltanet.io>
2018-06-19 17:59:53 +02:00
Donald Sharp 2bb9eff45f bgpd, lib: Cleanup CI warnings from system
Make the CI system happy.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2018-05-30 07:48:21 -04:00
mitesh 50f74cf131 *: support for evpn type-4 route
Signed-off-by: Mitesh Kanjariya <mitesh@cumulusnetworks.com>
2018-05-30 07:48:20 -04:00
mitesh 3714a3853c *: change struct evpn_addr to include a union of all evpn route types
EVPN prefix depends on the EVPN route type.
Currently, in FRR we have a prefix_evpn/evpn_addr which relates to a evpn prefix.
We need to convert this to encompass an union of various EVPN route-types.

This diff handles the necessary code changes to adopt the new struct evpn_addr.

Signed-off-by: Mitesh Kanjariya <mitesh@cumulusnetworks.com>
2018-05-02 17:49:17 -07:00
G. Paul Ziemba db2fde34d3 lib/prefix.[ch]: add family2str()
Signed-off-by: G. Paul Ziemba <paulz@labn.net>
2018-04-04 09:24:17 -07:00
Philippe Guibert 9a14899b0a lib: prefix support for flowspec
prefix structure is used to handle flowspec prefixes. A new AFI is
introduced: AF_FLOWSPEC. A sub structure named flowspec_prefix is
used in prefix to host the flowspec entry.
Reason to introduce that new kind is that prefixlen from prefix
structure is too short to all the flowspec needs, since NLRI can go over
0xff bytes.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2018-03-30 14:00:47 +02:00
Quentin Young d7c0a89a3a
*: use C99 standard fixed-width integer types
The following types are nonstandard:
- u_char
- u_short
- u_int
- u_long
- u_int8_t
- u_int16_t
- u_int32_t

Replace them with the C99 standard types:
- uint8_t
- unsigned short
- unsigned int
- unsigned long
- uint8_t
- uint16_t
- uint32_t

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
2018-03-27 15:13:34 -04:00
Lou Berger 996c93142d *: conform with COMMUNITY.md formatting rules, via 'make indent'
Signed-off-by: Lou Berger <lberger@labn.net>
2018-03-06 14:04:32 -05:00
Mladen Sablic 4d9ad5dcd0 pimd: Multicast traceroute client and router
This commit is the implementation of weak multicast traceroute.
It consists of IGMP module dealing with mtrace type IGMP messages
and client program mtrace/mtracebis for initiating mtrace queries.

Signed-off-by: Mladen Sablic <mladen.sablic@gmail.com>
2018-02-19 23:13:55 +01:00
Renato Westphal a37bd5e070 lib: fix more warnings on *BSD
* zebra/kernel_socket.c: include "rt.h" to provide the prototypes of
  kernel_init() and kernel_terminate();

* lib/prefix.h: remove the deprecation warning whenever ETHER_ADDR_LEN
  is used. isisd uses the ETHER_HDR_LEN constant which is defined in
  terms of ETHER_ADDR_LEN in the *BSD system headers. So, when building
  FRR on *BSD, we were getting several warnings because we were using
  ETHER_ADDR_LEN indirectly;

* lib/command_lex.l, lib/defun_lex.l: ignore other harmless warnings;

* lib/spf_backoff.c: cast 'tv->tv_usec' to 'long int' before printing.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
2018-02-02 16:31:20 -02:00
mitesh 523cafc418 bgpd, lib, zebra: fix style problems
Signed-off-by: Mitesh Kanjariya <mitesh@cumulusnetworks.com>
2017-12-27 11:47:10 -08:00
Mitesh Kanjariya 408b00c4d7 bgpd: only advertise valid subnet routes as evpn type-5 routes
Signed-off-by: Mitesh Kanjariya <mitesh@cumulusnetworks.com>
2017-12-14 10:57:08 -08:00
Mitesh Kanjariya b7cfce934f zebra, lib: zebra changes for symmetric routing support
Signed-off-by: Mitesh Kanjariya <mitesh@cumulusnetworks.com>
2017-12-14 10:56:44 -08:00
Donald Sharp f229873a87 *: Cleanup multiple is_default... code
There are 3 different implementations of is_prefix.
Standardize on is_prefix_default and fix it's implementation.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2017-08-31 16:11:17 -04:00
Donald Sharp 72a1b201d3 lib: Add PREFIX_COPY
Add a generic PREFIX_COPY to complement PREFIX_COPY_V4 and
PREFIX_COPY_V6

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2017-08-31 13:40:35 -04:00
David Lamparter d440e3dbf0 lib: prefix: fix char value size
There are 16 bytes here, not 8.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2017-08-26 01:46:40 +02:00
David Lamparter de1a880c4e lib: split off compiler magic into its own file
Also make timed notices available via CONFDATE.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2017-08-24 00:18:53 +02:00
Jorge Boncompte 19aad877b7 lib: optimize IPV4_ADDR_[SAME|COPY]()
Change all callers of IPV4_ADDR_SAME() to pass a pointer to a struct in_addr

Use assignment and comparison instead of memcpy() and memcmp(). Avoids function
calls. Faster.

Signed-off-by: Jorge Boncompte <jbonor@gmail.com>
2017-08-17 17:58:35 +02:00
David Lamparter 3b0f6068a8 lib: some final MAC access-list fixes
- couldn't load back written configs because it was trying to parse
  "any" as MAC address
- don't need special-casing in filter_match_zebra(), exact is going to
  be 0 for AF_ETHERNET anyway
- some vty formatting was slightly different
- is_zero_mac now static to prefix.c

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2017-08-09 20:30:34 +02:00
Donald Sharp 0f6476ccc3 lib, bgpd: Use 'struct prefix *' for filter matching
There is no need for special casing of mac addresses,
since the mac address is it's own type integrated
into `struct prefix` now.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2017-08-08 12:55:03 -04:00
Donald Sharp b03b88986e lib, bgpd: Distinguish between AF_EVPN and AF_ETHERNET
Create AF_EVPN for internal use and start using it.

Signed-off-by: Vivek Venkatraman <vivek@cumulusnetworks.com>
2017-08-08 10:34:31 -04:00
Mitesh Kanjariya 69b61704b8 lib: changes needed for mac access-list any command
Ticket: CM-17074
Review: CCR-6453
Unit-test: Manual

Signed-off-by: Mitesh Kanjariya <mitesh@cumulusnetworks.com>
2017-08-08 10:28:55 -04:00
Mitesh Kanjariya d37ba5499e bgpd, lib, vtysh: Added support for mac filtering in route-maps
1. Added support to create mac filters
2. Enabled route-map commands for EVPN address family
3. Provision to add mac filters under match clause in route-maps

Ticket: CM-16349
Review: CCR-6190
Unit-test: Manual (logs attached to ticket)

Signed-off-by: Mitesh Kanjariya <mitesh@cumulusnetworks.com>
2017-08-08 10:09:37 -04:00
Donald Sharp 7628d862ca lib: Add ETH_ALEN to prefix.h and deprecate ETHER_ADDR_LEN
From discussion we decided that we should use ETH_ALEN instead
of ETHER_ADDR_LEN.  Add ETH_ALEN to prefix.h and make
ETHER_ADDR_LEN generate a warning when used( but still work ).

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2017-08-04 09:06:14 -04:00
Christian Franke 7a7761d21c lib: move prefix hash key to prefix.c to allow global use
Signed-off-by: Christian Franke <chris@opensourcerouting.org>
2017-08-03 13:37:58 +02:00
David Lamparter 9d303b37d7 Revert "*: reindent pt. 2"
This reverts commit c14777c6bf.

clang 5 is not widely available enough for people to indent with.  This
is particularly problematic when rebasing/adjusting branches.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2017-07-22 14:52:33 +02:00
whitespace / reindent c14777c6bf
*: reindent pt. 2
w/ clang 5

* reflow comments
* struct members go 1 per line
* binpack algo was adjusted
2017-07-17 15:26:02 -04:00
whitespace / reindent d62a17aede *: reindent
indent.py `git ls-files | pcregrep '\.[ch]$' | pcregrep -v '^(ldpd|babeld|nhrpd)/'`

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2017-07-17 14:04:07 +02:00
Donald Sharp 7fb9d20fcf lib: Remove typedef from ipaddr
The ipaddr_t type was conflicting with code on omnios.

Remove the typedef

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2017-07-10 22:15:56 +02:00
David Lamparter 21bb7c8774 Merge commit '3d22338f04d9554fa' into evpn-prep
Conflicts:
	lib/Makefile.am

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2017-07-10 22:15:19 +02:00
Don Slice 3bec29ac95 lib/ospf/eigrp: enable ospf and eigrp to use more specific network statements
Issue reported that a configuration commonly used on other routing implementations
fails in frr.  If under ospf, "network 172.16.1.1/32 area 0" or under eigrp, "network
172.16.1.1/32" is entered, the appropriate interfaces are not included in the routing
protocol.  This was because the code was calling prefix_match, which did not match if
the network statement had a longer mask than the interface being matched.  This fix
takes away that restriction by creating a "lib/prefix_match_network_statement" function
which doesn't care about the mask of the interface.  Manual testing shows both ospf and
eigrp now can be defined with more specific network statements.

Signed-off-by: Don Slice <dslice@cumulusnetworks.com>
2017-06-28 14:57:36 -04:00
vivek 86f1ef44f7 lib: Refine EVPN prefix definition
Modify EVPN prefix to use the generic IP address structure. Add support
for EVPN type-2 and type-3 prefix dump. Fix references to modified fields
as needed.

Signed-off-by: Vivek Venkatraman <vivek@cumulusnetworks.com>
Reviewed-by:   Donald Sharp <sharpd@cumulusnetworks.com>
2017-05-25 10:20:03 -07:00
David Lamparter 5662e2c91c lib: fix __attribute__ typo
__attribute breaks pycparser

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2017-05-18 14:07:28 -04:00
David Lamparter 896014f4bc *: make consistent & update GPLv2 file headers
The FSF's address changed, and we had a mixture of comment styles for
the GPL file header.  (The style with * at the beginning won out with
580 to 141 in existing files.)

Note: I've intentionally left intact other "variations" of the copyright
header, e.g. whether it says "Zebra", "Quagga", "FRR", or nothing.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2017-05-15 16:37:41 +02:00
Don Slice cd1964ff38 bgpd: labeled unicast processing
Implement support for negotiating IPv4 or IPv6 labeled-unicast address
family, exchanging prefixes and installing them in the routing table, as
well as interactions with Zebra for FEC registration. This is the
implementation of RFC 3107.

Signed-off-by: Don Slice <dslice@cumulusnetworks.com>
2017-04-06 10:32:07 -04:00
Philippe Guibert db42a173d6 lib: simplify str2mac and use struct ethaddr structure
This commit simplified the string to mac conversion, since it uses
sscanf, instead of depicting each incoming character one by one, and
doing self analysis. Also,this commit changes the internal usage of the
mac address representation in mac handling function.

Signed-off-by: Lou Berger <lberger@labn.net>
Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2017-02-14 13:59:00 +01:00
Philippe Guibert d5c8a0cecf lib: append prefix_ for mac handling functions
This commit is changing the function naming for mac handling functions.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2017-02-14 13:59:00 +01:00
Philippe Guibert c215ecaf83 lib: add string to macaddress and reverse function
As mac-address structure is to be used as a prefix field, two new
functions permit handling mac address in order to convert it. either
from string to internal value, or the reverse operation.
Internal representation of a mac address is a 6 byte char value standing
for the 6 byte value the mac address has.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2017-02-14 13:58:59 +01:00
Philippe Guibert 0737aa5edb lib: remove HAVE_EVPN references
This commit removes references to HAVE_EVPN references in lib folder.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2017-02-14 13:58:59 +01:00
vivek 78b81eaa44 lib: Enhance prefix dump for EVPN prefixes
This commit is also taking into account changes related to srcdes
feature introduction in zebra folder.

Signed-off-by: Vivek Venkatraman <vivek@cumulusnetworks.com>
Reviewed-by:   Donald Sharp <sharpd@cumulusnetworks.com>
Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>

Ticket: CM-12262
Reviewed By: CCR-5065
Testing Done: Manual

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2017-02-14 13:58:58 +01:00
Philippe Guibert 79c0c95986 lib: afi_ether structure packing fix
'packed' keyword had no effect on packing the afi_ethernet structure.
The attribute keyword has been eppended in order to take into account
the packed feature.

Signed-off-by: Julien Courtat <julien.courtat@6wind.com>
2017-02-14 13:58:57 +01:00
Philippe Guibert 4470c22cad lib: add prefix support for evpn route type 5
The requirement from draft-ietf-bess-evpn-prefix-advertisement-03
mentions that the Eth-Tag ID, IP Prefix Length and IP Prefix will be
part of the route key used by BGP. The ip prefix length is then appended
to the evpn_addr. In addition to this, the ethernet tag ID is reused.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2017-02-14 13:58:57 +01:00
vivek a440846ea6 lib: EVPN prefix definition
Extend the prefix data structure to allow for basic support for EVPN type-3
and type-2 routes.

Note: This may be revised in future.

Signed-off-by: Vivek Venkatraman <vivek@cumulusnetworks.com>
Reviewed-by:   Donald Sharp <sharpd@cumulusnetworks.com>

Ticket: CM-11937
Reviewed By: CCR-5001
Testing Done: None

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2017-02-14 13:58:57 +01:00
David Lamparter dbb5a5552a lib: remove unused str2in6_addr()
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2017-02-08 16:33:47 +01:00
vivek a9ea959fae lib: Use single correct definition for prefix string buffer
Signed-off-by: Vivek Venkatraman <vivek@cumulusnetworks.com>
Reivewed-by:   Donald Sharp <sharpd@cumulusnetworks.com>

Ticket: CM-12262
Reviewed By: CCR-5065
Testing Done: Manual
2017-01-17 18:30:18 -05:00
Donald Sharp e921929069 lib: Setup prefix.h to allow it to store (s,g)
We need the ability to store the (s,g) in a struct prefix.
This will allow us to consolidate some duplicated code in
pimd as well as set us up to switch from a link list to a
table to store (s,g) state.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2017-01-17 18:26:43 -05:00
Donald Sharp 56c1f7d852 frr: Remove HAVE_IPV6 from code base
Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2017-01-13 08:05:50 -05:00
Lou Berger 32ac65d9fa lib: add AF_ETHERNET/AFI_ETHER 2016-09-03 11:05:51 -04:00
Timo Teräs 855110bb0b lib: make prefix2str simpler to use, and use it in zclient
Returning the buffer allows using it in the logging functions
in easier way. This also makes the API consistent with sockunion.

Add also PREFIX_STRLEN to be the generic buffer length required
for any prefix string representation.

Signed-off-by: Timo Teräs <timo.teras@iki.fi>
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
(cherry picked from commit 41eb9a4305fbcb206c900a18af7df7115d857d60)
2016-06-09 08:28:38 -04:00
Timo Teräs 40ee54a740 lib: allow caller to provide prefix storage in sockunion2hostprefix
Avoids a dynamic allocation which is usually freed immediate afterwards.

Signed-off-by: Timo Teräs <timo.teras@iki.fi>
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2016-06-09 08:21:40 -04:00
Lou Berger 1ec23d90a3 lib: add SAFI_ENCAP type, safi2str prefix utility
Signed-off-by: Lou Berger <lberger@labn.net>
(cherry picked from commit 2daf7f3a8d69213f35b16a04dbe300957481a811)
2016-05-26 15:33:33 +00:00
Christian Franke f3ccedaa3e isisd: add support to import routes from other protocols
Signed-off-by: Christian Franke <chris@opensourcerouting.org>
2016-03-29 20:26:28 -04:00
Donald Sharp 4690c7d74c Quagga: prefix2str fixup
During CR for nexthop upstream it was noticed that usage
of prefix2str was not consistent.  This fixes this problem

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
2015-11-23 13:31:11 -08:00
Feng Lu 78104b9bad zebra: let FIB stand for its respective VRF
A new member "vrf_id" is added to "struct rib", reflecting the VRF
which it belongs to.

A new parameter "vrf_id" is added to the relative functions where
need, except those:
- which already have the parameter "vrf_id"; or
- which have a parameter in type of "struct rib"; or
- which have a parameter in type of "struct interface".

All incoming routes are set to default VRF.

In fact, all routes in FIB are kept in default VRF. And the logic
is not changed.

Signed-off-by: Feng Lu <lu.feng@6wind.com>
Reviewed-by: Alain Ritoux <alain.ritoux@6wind.com>
Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
Acked-by: Vincent JARDIN <vincent.jardin@6wind.com>
[DL: conflicts fixed + compile warning fix]
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>

Conflicts:
	zebra/connected.c
	zebra/kernel_socket.c
	zebra/rib.h
	zebra/rt_netlink.c
	zebra/zebra_rib.c
	zebra/zserv.c

Conflicts:
	zebra/connected.c
	zebra/interface.c
	zebra/kernel_socket.c
	zebra/rib.h
	zebra/rt_netlink.c
	zebra/rtread_getmsg.c
	zebra/zebra_rib.c
	zebra/zebra_vty.c
	zebra/zserv.c
2015-10-29 23:38:03 -07:00
David Lamparter 5c6ed111e5 lib: fix "sockunion: add hash function" for BSD (9196caf)
The sockunion_hash() function uses s6_addr32, which is not defined on
BSD systems.  (It only works on glibc because we set _GNU_SOURCE)

ripngd/ripng_nexthop.h already contains a workaround for this.  Bump
workaround to prefix.h so it's available everywhere.

Reported-by: NetDEF CI System <mwinter@netdef.org>
Fixes: 9196caf ("sockunion: add hash function")
Cc: Timo Teräs <timo.teras@iki.fi>
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2015-09-08 13:19:30 -07:00
Donald Sharp 18ff3eddcc Zebra: Don't resolve nexthops over default route unless explicitly allowed.
Ensure that resolution of a nexthop using a default route is not done in the
nexthop validation/update code in zebra_rib.c also. This is an addition to
the zebra-nht-no-default.patch which made the checks only in the NHT code. In
the case of scenarios like interface down, this nexthop update code will kick
in first to update the route before the NHT code comes into play; without the
additional fix, this code could incorrectly resolve the nexthop over a default
route, even when disallowed by the administrator.
2015-06-11 09:11:12 -07:00
Donald Sharp d914d5ff0e Block martian address configuration on an interface and also block from
getting installed into the zebra tables.
2015-05-19 17:47:23 -07:00
Pradosh Mohapatra b4b359a265 ospfd: For an ABR, ensure the right LSID is MaxAge'd
PROBLEM:

Accurate garbage collection of maxage LSAs. The global OSPF structure has
a maxage_lsa tree - the key to the tree is <ls-id, adv-router> tuple. Suppose
the ABR has multiple areas and has originated some intra-area LSAs. The
key for all those LSAs is the same. The code then ends up in a state where
all but the first LSA do not get cleaned up from the areas' LSDB. A subsequent
event would readvertise those LSAs.

PATCH:

Since the LSA is going to stick around till it actually gets cleaned up by
the maxage_walker, make the LSA pointer as the key. Each distinct LSA that
gets maxage'd then gets added to the tree and will get cleaned up correctly.

Signed-off-by: Pradosh Mohapatra <pmohapat@cumulusnetworks.com>
[CF: Use CHAR_BIT; use uintptr_t; use sizeof(field) instead of sizeof(type)]
Signed-off-by: Christian Franke <chris@opensourcerouting.org>
[DL: this must remain a temporary fix! needs to be redone after 0.99.23]
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2014-05-14 16:46:41 +02:00
David Lamparter f7bf41534e zebra: apply syntactic sugar to rib_dump()
strip the explicit __func__ present on all calls and make the prefix
argument a transparent union.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2014-04-01 17:27:58 +02:00
Pradosh Mohapatra 6ee06fa9ed bgpd: bgpd-set-v4-nexthop-for-v6-peering.patch
BGP: While advertising v4 prefixes over a v6 session, set the correct v4 nexthop.

ISSUE:

For an IPv6 peer, BGPd sets the local router-id as the next-hop's v4 address.
This is incorrect as the router-id may not be a valid next-hop to be included
in UPDATEs that contain v4 prefixes.

PATCH:

Set the v4 address in the next-hop field based on the interface that the
peering is on (directly connected interface or loopback).

Signed-off-by: Pradosh Mohapatra <pmohapat at cumulusnetworks.com>
Reviewed-by: Scott Feldman <sfeldma at cumulusnetworks.com>
Acked-by: Feng Lu <lu.feng@6wind.com>
2014-02-10 09:37:30 +01:00
Paul Jakma f63f06da2e general: remove inline qualifiers and move in-header functions to objects
* (general) Move functions in headers into files, to be compiled into
  shared object files. Remove inline qualifier from functions. Let the
  compiler do the work.
2012-01-06 16:18:18 +00:00
Denis Ovsienko 733cd9e579 bgpd: justify checks for IPv4 class D/E
* lib/prefix.h
  * IPV4_CLASS_DE(): make consistent with counterpart macros
* bgp_packet.c
  * bgp_open_receive(): test using macro instead of ">="
* bgp_route.c
  * bgp_update_rsclient(): idem
  * bgp_update_main(): idem
2012-01-02 18:37:42 +04:00
Denis Ovsienko 21f569e37d lib: make masklen2ip6() safer and faster 2011-12-13 19:30:39 +04:00
Denis Ovsienko 9663386f16 lib: make masklen2ip() safer and faster 2011-12-13 19:30:17 +04:00
David Lamparter 17e52061ba lib: prefix2sockunion, prefix_common_bits helper functions
prefix2sockunion converts a struct prefix* to a union sockunion *;
prefix_common_bits counts the number of common bits in the prefix's
address part.
2011-11-21 19:41:51 +04:00
Denis Ovsienko bc3443ebf0 bgpd: improve NEXT_HOP attribute checks (BZ#680)
* lib/prefix.h
  * IPV4_CLASS_DE(): new helper macro
* bgp_attr.c
  * bgp_attr_nexthop(): add check for "partial" bit, refresh flag error
    reporting, explain meaning of RFC4271 section 6.3 and implement it

Conflicts:

	bgpd/bgp_attr.c
2011-09-30 01:24:35 +04:00
Michael Lambert 4c9641ba4d bgpd, lib: adopt afi_t and safi_t in several places
* bgpd/bgp_attr.c, bgpd/bgp_open.h, bgpd/bgp_route.c, lib/prefix.c,
  lib/prefix.h: Various integer types were being used where, if we
  had strict type checking, afi_t and safi_t would be required.

Signed-off-by: G.Balaji <balajig81@gmail.com>
(cherry picked from commit c8af35ffa2dc79ff7d7ff00b1b61f1f50a100ab6)
2010-10-06 12:33:05 -04:00
Stephen Hemminger 813f6a0064 ospf6d: fix warnings from recent prefix bit commit
* lib/prefix.h
  * prefix6_bit(): add IPv6 wrapper for prefix_bit()
* ospf6d/ospf6_lsdb.c
  * ospf6_lsdb_type_router_head(): employ prefix6_bit()
  * ospf6_lsdb_type_head(): idem
2009-12-10 16:13:09 +03:00
Stephen Hemminger 1352ef32d7 lib: move check_bit into prefix common code
Make one version of check prefix bit, and put it inline
with proper prototype. This gets rid of some macro's and also some
assert() that can never happen on a non-broken compiler.

* bgpd/bgp_table.c
  * CHECK_BIT(): sayonara
  * check_bit(): sayonara
  * SET_LINK(): sayonara
  * set_link(): make use of prefix_bit() instead of check_bit()
  * bgp_node_match(): idem
  * bgp_node_lookup(): idem
  * bgp_node_get(): idem
* lib/prefix.h
  * prefix_bit(): new inline version of check_bit()
* lib/table.c
  * CHECK_BIT(): sayonara
  * check_bit(): sayonara
  * SET_LINK(): sayonara
  * set_link(): make use of prefix_bit() instead of check_bit()
  * route_node_match(): idem
  * route_node_lookup(): idem
  * route_node_get(): idem
* ospf6d/ospf6_lsdb.c
  * CHECK_BIT(): sayonara
  * ospf6_lsdb_lookup_next(): make use of prefix_bit() instead of
    CHECK_BIT()
  * ospf6_lsdb_type_router_head(): idem
  * ospf6_lsdb_type_head(): idem
* ospf6d/ospf6_route.c
  * CHECK_BIT(): sayonara
  * ospf6_route_match_head() make use of prefix_bit() instead of
  * CHECK_BIT()
2009-12-09 14:43:17 +03:00
Paul Jakma 6dc686a29e [zebra] Bug #351: Don't redistribute routes to ipv4 link-local prefixes
2007-04-07 Paul Jakma <paul.jakma@sun.com>

	* lib/prefix.h: Add define to match IPv4 Link-Local addresses
	* zebra/redistribute.c: (zebra_check_addr) Don't redistribute routes
	  to IPv4 link-local prefixes, fixes bug #351.
	* zebra/redistribute.h: Export zebra_check_addr.
	* zebra/router-id.c: (router_id_bad_address) re-use zebra_check_addr
	  rather than implementing similar logic.
2007-04-10 19:24:45 +00:00
Andrew J. Schorr e4529636b7 [PtP over ethernet] New peer flag allows much more addressing flexibility
2006-12-12 Andrew J. Schorr <ajschorr@alumni.princeton.edu>

	* if.h: (struct connected) Add new ZEBRA_IFA_PEER flag indicating
	  whether a peer address has been configured.  Comment now shows
	  the new interpretation of the destination addr: if ZEBRA_IFA_PEER
	  is set, then it must contain the destination address, otherwise
	  it may contain the broadcast address or be NULL.
	  (CONNECTED_DEST_HOST,CONNECTED_POINTOPOINT_HOST) Remove obsolete
	  macros that were specific to IPv4 and not fully general.
	  (CONNECTED_PEER) New macro to check ZEBRA_IFA_PEER flag.
	  (CONNECTED_PREFIX) New macro giving the prefix to insert into
	  the RIB: if CONNECTED_PEER, then use the destination (peer) address,
	  else use the address field.
	  (CONNECTED_ID) New macro to come up with an identifying address
	  for the struct connected.
	* if.c: (if_lookup_address, connected_lookup_address) Streamline
	  logic with new CONNECTED_PREFIX macro.
	* prefix.h: (PREFIX_COPY_IPV4, PREFIX_COPY_IPV6) New macros
	  for better performance than the general prefix_copy function.
	* zclient.c: (zebra_interface_address_read) For non-null destination
	  addresses, set prefixlen to equal the address prefixlen.  This
	  is needed to get the new CONNECTED_PREFIX macro to work properly.
	* connected.c: (connected_up_ipv4, connected_down_ipv4,
	  connected_up_ipv6, connected_down_ipv6) Simplify logic using the
	  new CONNECTED_PREFIX macro.
	  (connected_add_ipv4) Set prefixlen in destination addresses (required
	  by the CONNECTED_PREFIX macro).  Use CONNECTED_PEER macro instead
	  of testing for IFF_POINTOPOINT.  Delete invalid warning message.
	  Warn about cases where the ZEBRA_IFA_PEER is set but no
	  destination address has been supplied (and turn off the flag).
	  (connected_add_ipv6) Add new flags argument so callers may set
	  the ZEBRA_IFA_PEER flag.  If peer/broadcast address satisfies
	  IN6_IS_ADDR_UNSPECIFIED, then reject it with a warning.
	  Set prefixlen in destination address so CONNECTED_PREFIX will work.
	* connected.h: (connected_add_ipv6) Add new flags argument so
	  callers may set the ZEBRA_IFA_PEER flag.
	* interface.c: (connected_dump_vty) Use CONNECTED_PEER macro
	  to decide whether the destination address is a peer or broadcast
	  address (instead of checking IFF_BROADCAST and IFF_POINTOPOINT).
	* if_ioctl.c: (if_getaddrs) Instead of setting a peer address
	  only when the IFF_POINTOPOINT is set, we now accept a peer
	  address whenever it is available and not the same as the local
	  address.  Otherwise (no peer address assigned), we check
	  for a broadcast address (regardless of the IFF_BROADCAST flag).
	  And must now pass a flags value of ZEBRA_IFA_PEER to
	  connected_add_ipv4 when a peer address is assigned.
	  The same new logic is used with the IPv6 code as well (and we
	  pass the new flags argument to connected_add_ipv6).
	  (if_get_addr) Do not bother to check IFF_POINTOPOINT: just
	  issue the SIOCGIFDSTADDR ioctl and see if we get back
	  a peer address not matching the local address (and set
	  the ZEBRA_IFA_PEER in that case).  If there's no peer address,
	  try to grab SIOCGIFBRDADDR regardless of whether IFF_BROADCAST is set.
	* if_ioctl_solaris.c: (if_get_addr) Just try the SIOCGLIFDSTADDR ioctl
	  without bothering to check the IFF_POINTOPOINT flag.  And if
	  no peer address was found, just try the SIOCGLIFBRDADDR ioctl
	  without checking the IFF_BROADCAST flag.  Call connected_add_ipv4
	  and connected_add_ipv6 with appropriate flags.
	* if_proc.c: (ifaddr_proc_ipv6) Must pass new flags argument to
	  connected_add_ipv6.
	* kernel_socket.c: (ifam_read) Must pass new flags argument to
	  connected_add_ipv6.
	* rt_netlink.c: (netlink_interface_addr) Copy logic from iproute2
	  to determine local and possible peer address (so there's no longer
	  a test for IFF_POINTOPOINT).  Set ZEBRA_IFA_PEER flag appropriately.
	  Pass new flags argument to connected_add_ipv6.
	  (netlink_address) Test !CONNECTED_PEER instead of if_is_broadcast
	  to determine whether the connected destination address is a
	  broadcast address.
	* bgp_nexthop.c: (bgp_connected_add, bgp_connected_delete)
	  Simplify logic by using new CONNECTED_PREFIX macro.
	* ospf_interface.c: (ospf_if_is_configured, ospf_if_lookup_by_prefix,
	  ospf_if_lookup_recv_if) Simplify logic using new CONNECTED_PREFIX
	  macro.
	* ospf_lsa.c: (lsa_link_ptop_set) Using the new CONNECTED_PREFIX
	  macro, both options collapse into the same code.
	* ospf_snmp.c: (ospf_snmp_if_update) Simplify logic using new
	  CONNECTED_ID macro.
	  (ospf_snmp_is_if_have_addr) Simplify logic using new CONNECTED_PREFIX
	  macro.
	* ospf_vty.c: (show_ip_ospf_interface_sub) Use new CONNECTED_PEER macro
	  instead of testing the IFF_POINTOPOINT flag.
	* ospfd.c: (ospf_network_match_iface) Use new CONNECTED_PEER macro
	  instead of testing with if_is_pointopoint.  And add commented-out
	  code to implement alternative (in my opinion) more elegant behavior
	  that has no special-case treatment for PtP addresses.
	  (ospf_network_run) Use new CONNECTED_ID macro to simplify logic.
	* rip_interface.c: (rip_interface_multicast_set) Use new CONNECTED_ID
	  macro to simplify logic.
	  (rip_request_interface_send) Fix minor bug: ipv4_broadcast_addr does
	  not give a useful result if prefixlen is 32 (we require a peer
	  address in such cases).
	* ripd.c: (rip_update_interface) Fix same bug as above.
2006-12-12 19:18:21 +00:00
paul 8cc4198f9f 2005-05-06 Paul Jakma <paul@dishone.st>
* (general) extern and static'ification of functions in code and
	  header.
	  Cleanup any definitions with unspecified arguments.
	  Add casts for callback assignments where the callback is defined,
	  typically, as passing void *, but the function being assigned has
	  some other pointer type defined as its argument, as gcc complains
	  about casts from void * to X* via function arguments.
	  Fix some old K&R style function argument definitions.
	  Add noreturn gcc attribute to some functions, as appropriate.
	  Add unused gcc attribute to some functions (eg ones meant to help
	  while debugging)
	  Add guard defines to headers which were missing them.
	* command.c: (install_node) add const qualifier, still doesnt shut
	  up the warning though, because of the double pointer.
	  (cmp_node) ditto
	* keychain.c: (key_str2time) Add GET_LONG_RANGE() macro, derived
	  fromn vty.h ones to fix some of the (long) < 0 warnings.
	* thread.c: (various) use thread_empty
	  (cpu_record_hash_key) should cast to uintptr_t, a stdint.h type
	* vty.h: Add VTY_GET_IPV4_ADDRESS and VTY_GET_IPV4_PREFIX so they
	  removed from ospfd/ospf_vty.h
	* zebra.h: Move definition of ZEBRA_PORT to here, to remove
	  dependence of lib on zebra/zserv.h
2005-05-06 21:25:49 +00:00
hasso 3a2ce6a14e * prefix.[hc]: Pass argument to the inet6_ntoa by value making it more
inet_ntoa alike.
	* ripngd.[hc], ripng_interface.c, ripng_peer.c: inet6_ntoa() takes
	  argument now by value.
2005-04-08 01:30:51 +00:00
hasso 5920990fec * lib/prefix.[hc]: inet6_ntoa utility function copied from
ripngd/ripngd.c (inet6_ntop).
	* ripngd.[hc]: Remove inet6_ntop() and any usage of it. inet6_ntoa()
	  from lib is used now.
	* ripng_interface.c: inet6_ntop() -> inet6_ntoa().
	* ripng_peer.c: inet6_ntop() -> inet6_ntoa().
2005-04-05 14:36:49 +00:00
hasso 3fb9cd6ef4 OK. Here it is - PtP patch from Andrew J. Schorr. No problems with ospfd,
ripd might need some more testing though.
2004-10-19 19:44:43 +00:00
hasso b04c699ecf First small part of lib cleanup. Mainly "constification" of arguments and
adding FIXME's.
2004-10-04 19:10:31 +00:00
gdt 9d24baaa3d Explain the dual use of struct prefix for CIDR prefixes and
address/netmask pairs, and clarify the two comparison functions.
2004-01-13 14:55:40 +00:00
paul 718e374419 Initial revision 2002-12-13 20:15:29 +00:00